There's more than one way to do things | |
PerlMonks |
Re: panic: restartop error using Perl Tk + fork() on Win32.by BrowserUk (Patriarch) |
on Oct 10, 2005 at 07:23 UTC ( [id://498731]=note: print w/replies, xml ) | Need Help?? |
As metioned above, fork is emulated under Win32(using threads). So both branches of the fork are threads within the same process. When you then exec your command, the entire process is replaced by the exec'd command, which isn't very useful. To avoid that problem, skip fork completely (just forking and doing nothing is enough to crash Tk;), and use system 1, 'wish temp.tcl'; to run the command asynchronously. That works, but doesn't give you the opportunity to retrieve the return code from the command if that is important to you. If you need that, you can use threads::async, to run system synchronously in a thread, but asynchronously from the Tk thread. The following snippet will run the command from the edit field via system in a thread, retrieve the return code and post it to the tk screen. The progress bar is there to show that the tk interface doesn't stall. Indeed, you can click 'Doit' several times and multiple copies of the command will run concurrently:
When you terminate the tk window, you will see the following errors displayed:
The first I have no idea about but is probably related to the second. The second is a consequence of using tk and threads together, but it only occurs when the app is terminating anyway and does not appear from my scant tests to indicate anything that would prevent the app from running correctly and completing successfully. 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.
In Section
Seekers of Perl Wisdom
|
|