is it a thread problem?



Iam using threads in gtk2.My application is doing transfer files(IO::Ftp) with progressbars updation using threads.
But it is showing error as Thread failed to start:Gdk-ERROR assertion failed and Could not read memory at progressbar6->set_fraction($totalpercent)in my code.


Can any one suggest that how to solve this problem. Here iam giving part of my code. split_file is another subroutine which splits the file into 5 parts.



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 = "">      $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;
           
    #Taking only filename from the path
    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;
      print "C is $completed\n";
      $finished += $n;
      print "F is : $finished\n";     
      # % xferred
      my $percent = $completed / $file_size;
      $progressbar[$count]->set_fraction($percent);
      #~ my $totalpercent = $finished / $totalfilesize;
      #~ print "Total is $totalpercent\n";
      #~ if($totalpercent <= 1)
      #~ {
         #~ $progressbar6->set_fraction($totalpercent);
      #~ }
      undef($buffer);
      if($ftp_die == 1)
      {
        $ftp->close;
        $ftp->delete($filename);
        unlink($filename);     
        &clear_progressbars;
        print "File deleted\n";
        return;
      }
     }
      if($finished == $totalfilesize )#or $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)
      {
           my $totalpercent = $finished / $totalfilesize;
           print "Total is $totalpercent\n";
           if($totalpercent > 1)
           {
               print "total exceeds one\n";
               $totalpercent = 1;
           }  
           if($totalpercent <= 1)
           {
            $progressbar6->set_fraction($totalpercent);
           }
           if($totalpercent >= 1)
           {
               $is_filexfer = 0 ;
               sleep(1);
           }
      }
       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++;
       }
      sleep(2);
      $list->remove($iter) if defined($iter);
      }
    } 
}
sub transfer_file_cb
{
      my $thread = new threads(\&transfer_file,\ _);
      push (@threads, $thread);
}    
   
 # wait for the children to finish...
foreach (@threads)
{
      $_->join;
           





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]