Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Perl/Tk App and Interprocess Communication

by beretboy (Chaplain)
on Jun 30, 2005 at 15:03 UTC ( #471357=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl/Tk App and Interprocess Communication
in thread Perl/Tk App and Interprocess Communication

Thanks for taking the time to write that, you've saved me a huge headache. UPDATE: I've never worked with threads in perl, could you point me towards some resources dealing with that? UPDATE UPDATE: Reading Camel Book chapter now, nevermind. Thanks again! UPDATE UPDATE UPDATE: Okay, I'd really appreciate a walkthrough of how this works, and how you can prevent it from "missing" data. If I bump the timer up to 1 second it jumps over big swaths of numbers.



"Sanity is the playground of the unimaginative" -Unknown


Comment on Re^2: Perl/Tk App and Interprocess Communication
Re^3: Perl/Tk App and Interprocess Communication
by BrowserUk (Pope) on Jun 30, 2005 at 18:25 UTC

    Okay. The code I posted will miss intermediate values if the incoming values arrive faster than the screen update checks for them.

    If your application need to reflect every change, and if it can update the screen as fast or faster than the input arrives, that would not occur.

    If you cannot update the screen as fast as the input arrives, then eventually you will have to either combine multiple inputs into a single update, or discard intermediates.

    Either way, to ensure than your update thread sees all the inputs, it must either run faster than the inputs arrive, or they must be queued

    Here is a queued solution.

    #!perl -slw use strict; use threads qw[ async ]; use Thread::Queue; ## A shared var to communicate progess between work thread and TK my $Q = new Thread::Queue; sub work{ open PROC, 'perl -le"$|=1; print and select(undef,undef,undef,0.1) for 1 .. 1 +000" |' or die $!; while( <PROC> ) { $Q->enqueue( $_ ); } close PROC; } threads->new( \&work )->detach; ## For lowest memory consumption require (not use) ## Tk::* after you've started the work thread. require Tk::ProgressBar; my $mw = MainWindow->new; my $pb = $mw->ProgressBar()->pack(); my $repeat; $repeat = $mw->repeat( 100 => sub { while( $Q->pending ) { my $progress = $Q->dequeue; return unless $progress; $repeat->cancel if $progress == 100; $pb->value( $progress ) } } ); $mw->MainLoop;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-09-22 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (188 votes), past polls