Is it a gtk2 problem or Threads problem

Discussion in 'Perl Misc' started by prameela, Mar 19, 2006.

  1. prameela

    prameela Guest

    Hai All,


    In my application iam using threads under Gtk2.Iam trnsferring
    files with progressbars updation using threads.Some one suggested me to
    use Gtk2 qw/-init -threads-init/; If i used this, the application is
    hanging(means the widgets are not visible).Iam using only use threads
    and use threads ::shared.In this it is giving error(cannot read memory
    error) at Progressbar6->set_fraction($totalpercent);

    Can any one suggest me how to do this??? and What is Gdk assertion
    failed error.

    please give answer as early as possible

    In the below code get_value is a thread code block in which iam
    callling another threads.Is it corrct or not.


    sub on_btnAddToXfer_clicked
    {
    my $filename = get_selected_file;
    my $model = $lstXferQ->get_model;
    my $new_iter = $model->append;
    $model->set($new_iter, 0 => $filename);
    print "File is $filename\n";
    my $data = get_story_data_from_widgets;
    $fnames{$filename} = $data;

    $thread = new threads(\&get_value,$filename) unless
    (defined($thread));
    }

    sub transfer_file
    {
    my $arrayref = shift;
    my $filename = @$arrayref[0];
    my $count = @$arrayref[1];
    print "FILE IS : $filename\n";
    my $file_size = -s $filename;
    my $org_file;

    if($filename =~ /([A-Za-z0-9_-]*\.mpg)$/)
    {
    $org_file = $1;

    }
    open(FD,"$filename") or die "cannot open file: $!";
    binmode(FD);
    my $completed;
    my
    $ftp=IO::Ftp->new(">","//user:usr1234\@callista.ueltv.org/squick/$org_file",TYPE=>'i');
    my $n;
    my $buffer;
    while($n = read(FD,$buffer,4*1024*1024))
    {
    $ftp->send($buffer);
    $completed += $n;
    $finished += $n;

    # % xferred

    my $percent = $completed / $file_size;
    #Gtk2::Gdk::Threads->enter;
    $progressbar[$count]->set_fraction($percent);(SOME TIMES IT IS
    GIVING ERROR HERE ALSO)
    #Gtk2::Gdk::Threads->leave;
    undef($buffer);
    if($ftp_die == 1)
    {
    $ftp->close;
    $ftp->delete($filename);
    unlink($filename);
    &clear_progressbars;
    print "File deleted\n";
    return;
    }
    }
    if($finished == $totalfilesize)
    {
    sleep(1);
    $finished = 0;
    print "cleared\n";
    &clear_progressbars;
    }
    close(FD);
    # Deleting temporary files from the Directory
    unlink($filename);
    }


    sub get_value
    {
    print "Monitoring...\n";
    while(1)
    {
    next unless (defined($list));
    my $iter = $list->get_iter_first;
    my $filename = $list->get($iter, 0) if defined($iter);
    if($is_filexfer ==1)
    {
    print "Finished is $finished\n";
    my $totalpercent = $finished / $totalfilesize;
    print "Total is $totalpercent\n";
    if($totalpercent > 1)
    {
    print "total exceeds one\n";
    $totalpercent = 1;
    sleep(1);
    &clear_progressbars;
    }
    eval
    {
    if($totalpercent <= 1)
    {
    $progressbar6->set_fraction($totalpercent); ( #HERE IT
    IS GIVING CANNOT READ MEMORY ERROR)
    }
    };
    if ($@)
    {
    print "Error occur at $@,continuing\n";
    }
    if($totalpercent >= 1)
    {
    $is_filexfer = 0 ;
    sleep(1);
    }
    } #if xfer

    if($is_filexfer == 0)
    {
    next unless(defined($filename));
    print"File name is : $filename\n";
    print "Splitting file...\n";
    my $filenames_ref = split_file($filename);
    my @filenames = @$filenames_ref;
    $count = 0;
    $finished = 0;
    foreach (@filenames)

    {
    print "Transferring $_ ...\n";

    transfer_file_cb($_,$count);

    $is_filexfer = 1 ;
    $count++;
    }#foreach
    sleep(2);
    $list->remove($iter) if defined($iter);
    }#if close
    } # while
    } # sub

    sub transfer_file_cb
    {
    my $thread = new threads(\&transfer_file,\@_);
    push (@threads, $thread);
    }

    # wait for the children to finish...
    foreach (@threads)
    {
    $_->join;

    }
     
    prameela, Mar 19, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. oxman
    Replies:
    1
    Views:
    107
    oxman
    Aug 15, 2003
  2. David Espada
    Replies:
    2
    Views:
    132
    David Espada
    Apr 28, 2004
  3. Krisztian VASAS

    problem between perl-gtk2 and POE::Session

    Krisztian VASAS, Jun 21, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    105
    Rocco Caputo
    Jun 24, 2004
  4. prameela

    how to use gtk2 threads

    prameela, Mar 20, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    341
    zentara
    Mar 20, 2006
  5. prameela

    how to use gtk2 threads

    prameela, Mar 20, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    99
    prameela
    Mar 20, 2006
Loading...

Share This Page