Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Is it a gtk2 problem or Threads problem

Reply
Thread Tools

Is it a gtk2 problem or Threads problem

 
 
prameela
Guest
Posts: n/a
 
      03-19-2006
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;

}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use gtk2 threads prameela Perl Misc 1 03-20-2006 12:13 PM
how to use gtk2 threads prameela Perl Misc 0 03-20-2006 10:21 AM
problem between perl-gtk2 and POE::Session Krisztian VASAS Perl Misc 1 06-24-2004 02:03 AM
[ruby-gtk2] problem changing menu in Gtk::OptionMenu David Espada Ruby 2 04-28-2004 07:35 PM
Gtk2: stange problem with notebook ? oxman Ruby 1 08-15-2003 08:08 AM



Advertisments