Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Perl/Tk and Threads

by Streen (Sexton)
on Jun 17, 2004 at 12:22 UTC ( #367593=perlquestion: print w/replies, xml ) Need Help??
Streen has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem regarding Perl/Tk and Threads,
I made a GUI with TK and from this GUI I am calling a module which has a long runtime. Now I would like to display some status messages about this module, how far it reached.
I tried to make this with Threads, but this won't function.
sub run { #this is called via a button from the GUI #Call the Module $threadRun = Thread -> new (\&printExcel::Edit, $option,$path); #print the status &printStatus(); } sub printStatus { print "\n\n\n\n\n\nprint status\n"; #hier hol ich mir den neuen status my @NewStatus = &printExcel::GetStatus(); print "new status: @NewStatus\n"; #now wait 5 seconds an call yourself $Basic_wd -> after (5000, &printStatus(@NewStatus)); }
I know the "printStatus" sub is an endless loop, but this is not the problem. The problem is, when i call the thread, the sub defined in the thread is called, the "printStatus" sub is also called, but only once.
The sub "&printExcel::Edit" runns and when it finished, the whole Gui freezes and the progam is hooked. Has anyone some suggetstions what i made wrong or how I could solve this problem?

Replies are listed 'Best First'.
Re: Perl/Tk and Threads
by gri6507 (Deacon) on Jun 17, 2004 at 13:24 UTC
    One way to do it would be to fork off another process which would communicate to the parent through a socket and have the parent test the socket with select() in a repeat() event. Take a look at the code (untested snipets of an older app).

Re: Perl/Tk and Threads
by zentara (Archbishop) on Jun 17, 2004 at 14:37 UTC
    The first thought that comes to me is to use a repeat statement instead of your "after". Sometimes you just have to use "trial and error" and try alot of different approaches.
    my $id; #setup a global for the repeat so you can cancel #from anywhere in the script sub run { #this is called via a button from the GUI #Call the Module # update: also try to start the repeat here, before the # thread start $threadRun = Thread -> new (\&printExcel::Edit, $option,$path); #print the status $id = repeat(5000, \&printStatus() ); } sub printStatus { print "\n\n\n\n\n\nprint status\n"; #hier hol ich mir den neuen status my @NewStatus = &printExcel::GetStatus(); print "new status: @NewStatus\n"; }

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://367593]
Approved by gri6507
help
Chatterbox?
[stevieb]: nice! I just finished a GPS "take me home" device last week, and did a bunch of software updates to it yesterday. I also created a pseudo chip with an Arduino to simulate an IC, where it responds to register read/writes over the I2C bus...
[stevieb]: ...from an I2C master. It's ugly and there are many changes I'm going to make, but I had not done anything like it before. It's designed for my RPi:: automated test platform; a system that does CI on *all* my RPi modules.
[shmem]: pseudo chip?
[stevieb]: well, what happens is the Arduino 'listens' for requests r/w, and does the appropriate thing when it's interrupted based on the 'register' address sent in. It's ugly as it was my first attempt, but I've got great new ideas I'm just sitting.
[stevieb]: ...down to implement now. Here's the sketch as it currently sits
[shmem]: well I use I2C and SPI and stuff, but creating a pseudo chip looks to me like lot of indirection and memory clutter... not?
[choroba]: Are you going to use the device soon? Related to your comment about "not having much time to do a lot of coding"...
[stevieb]: sure, but I'm just learning ;) I consider it practice to get a good understanding of what goes on *after* an I2C/SPI request is made
[shmem]: ah ok. Gonna read that. but now....
shmem compiles himself into his template

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-06-25 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (572 votes). Check out past polls.