Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Threading Problems

by jerre_111 (Sexton)
on Apr 23, 2013 at 08:37 UTC ( #1030073=note: print w/ replies, xml ) Need Help??


in reply to Re: Threading Problems
in thread Threading Problems

Thanks, I'll take a look at the node you have send.

Yes, I'm using Perl/Tk. Drawing the Progress bar is already done, it is the updating in the thread that doesn't work out for me.

Thanks for your advice

Update

Hmm I don't seem to get any wiser from the node you have send me sorry. I'm sure it is me but, I could only find one answer about using threads ine that node, and I didn't understand it sorry.

All the rest was about using a spinner as a progress indicator. Butt, I use the Tk::ProgressBar because I want to show a percentage of the work that is done already.

Sorry for being such a retard, Threading is not my thing is seems


Comment on Re^2: Threading Problems
Re^3: Threading Problems
by kcott (Abbot) on Apr 24, 2013 at 07:15 UTC
    "... I could only find one answer about using threads ine that node, and I didn't understand it sorry."

    Perhaps a look at the Perl Threads Tutorial might help.

    Here's a technique for creating image data and updating a progress bar without using threads. I've made no attempt to integrate canvasses, rectangles, etc. This is a complete working script — you should be able to run it as is.

    #!/usr/bin/env perl use strict; use warnings; use Tk; use Tk::Photo; use Tk::ProgressBar; my $mw = MainWindow->new(); $mw->geometry("200x200"); my $action_F = $mw->Frame()->pack(-side => 'bottom'); my $exit_B = $action_F->Button(-text => 'Exit', -command => sub { exit + })->pack; my $image_F = $mw->Frame( )->pack(-padx => 10, -pady => 10, -expand => 1, -fill => 'both'); my $progress_F = $mw->Frame( )->pack(-padx => 10, -pady => 10, -expand => 0, -fill => 'x'); my ($image_height, $image_width) = (100, 100); my $image = $image_F->Photo(-height => $image_height, -width => $image +_width); $image_F->Label(-image => $image)->pack; my $pc_image_drawn = 0; my $progress_PB = $progress_F->ProgressBar(-variable => \$pc_image_dra +wn )->pack(-fill => 'x'); for my $height (0 .. $image_height - 1) { for my $width (0 .. $image_width - 1) { $image->put('#ffcc33', -to => $width, $height); $image->update; # called in inner loop for slow demonstration +display } $pc_image_drawn = (($height + 1) / ($image_height)) * 100; } MainLoop;

    -- Ken

      Thank you very much for your help!

      In the meanwhile I have found that Tk isn't thread safe at all if I'm correct, so I think its not a good idea using threads to update a Progress Bar.

      I'm using a progress bar also without thread now, but the main issue about this is that is slows my program quite a bit. I'm still looking for a way to speed things up.

      Many thanks for your help and time kcott! I appreciate all your effort.

      Greetings

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030073]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-04-17 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (445 votes), past polls