Is it a gtk2 problem or Threads problem

P

prameela

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;

}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top