x-lours has asked for the wisdom of the Perl Monks concerning the following question:
i use perl v5.12.4 from activeperl
i try a script which copy many distants files (with "pscp" from 'PUTTY' because i can't use ppm at my job) on my disk if the user answers "yes" to a question (using Tkx::tk___messageBox)
the script run nearly good and i put some threads, with detach, inside to avoid waiting for some files before asking for the others.
but now i got a problem with one file about 108Mo.
i got the message "DeleteInterpProc called with active evals" after the loading of this file and the script stop.
because of the detach, if i go fast enough, i can get the others files but ...
in google, i found some page about "DeleteInterpProc called with active evals" talking over TCL.
is there a way to avoid the error ?
Thanks in advance for any suggestions and for any comment permiting to go further
x-l_ours
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threads and TCL DeleteInterpProc
by zentara (Cardinal) on Jun 13, 2014 at 09:26 UTC | |
This is just a basic piece of advice when running threads from a gui. Most GUI's are not thread safe, meaning you should not invoke any GUI code BEFORE launching your threads. This is because perl threads copy the entire parent process when they are initiated, and if GUI code is already in the main code, you get multiple ( often error causing) copies of the gui code in the different threads. Now some GUI toolkits do offer some thread safety, like Gtk2, Gtk3, and others based on the Glib system. I don't know about your gui toolkit, but I would guess it's non-thread-safety the source of the problem. The most reliable way to avoid the issue, is to create all your threads before any GUI code is invoked in your parent, AND do not put any GUI code into your threads. I only have an example with Tk , but it should show you the idea. See Re: Perl Tk and Threads or you can google for "perl tk thread safety" and get alot of examples. I'm not really a human, but I play one on earth. Old Perl Programmer Haiku ................... flash japh | [reply] |
by Anonymous Monk on Jun 13, 2014 at 09:45 UTC | |
| [reply] [d/l] |
by x-lours (Sexton) on Jun 17, 2014 at 14:11 UTC | |
i will search in this way, in french of course ;-) i don't know much about GUI but in my script i HAVE to alternate between asking user and launching thread if needed.i could try the questions and close the widgets BEFORE launching the threads but not the opposite i will follow the investigation ;-) | [reply] |
by zentara (Cardinal) on Jun 17, 2014 at 21:41 UTC | |
The idea is to launch as many worker threads as you think you need, right at the beginning, and put them into a sleep loop until you want to wake them. Then make your gui code, and wake up and feed the pre-made threads your command to perform. Finally always program a way so that you can reuse your workers, instead of killing them off and creating new ones. Just for your education, you can pass strings to your threads to be eval'd, this makes it easy to reuse threads. For example, look at the simple thread code in this example. You can ask your questions at anytime after the threads are formed, and pass in code to be eval'd by the thread, thru a shared variable. Finally, Gtk2 does have some thread safety built-in, allowing you to make widgets as the threads are formed, but it is full of difficulty to get it right. Even in Gtk2, the advice remains the same, make your threads first, before gui code.
I'm not really a human, but I play one on earth. Old Perl Programmer Haiku ................... flash japh | [reply] [d/l] |
by x-lours (Sexton) on Jun 30, 2014 at 09:08 UTC | |
by x-lours (Sexton) on Jun 26, 2014 at 09:44 UTC | |
|
Re: Threads and TCL DeleteInterpProc
by InfiniteSilence (Curate) on Jun 12, 2014 at 16:39 UTC | |
Some source code perhaps? Celebrate Intellectual Diversity | [reply] |
by x-lours (Sexton) on Jun 13, 2014 at 08:07 UTC | |
all my code :
| [reply] [d/l] |
|
Re: Threads and TCL DeleteInterpProc
by Anonymous Monk on Jun 12, 2014 at 23:44 UTC | |
is there a way to avoid the error ? Yes, write better code :) something about managing exit and interpreter life ... probably Tkx foolishness | [reply] |
by x-lours (Sexton) on Jun 13, 2014 at 08:13 UTC | |
have you any suggestion ? i put my code as a reply of the other answer. if you have any suggestion about better code i'll be happy to learn it ;-)thanks for taking care | [reply] |
by Anonymous Monk on Jun 13, 2014 at 09:32 UTC | |
A question for you, how far does your program go before the Tcl error shows up? Devel::Trace Reminds me of Re^3: TKX and closing windows (bug) .. L'anana ne parlais pas .... so this is the way I'd structure the program to avoid any Tkx noise .... I don't see an use for Thread::Semaphore Read more... (2 kB)
As you can see, the more well named subs you have, the less comments you need See also Ask - ask your users about stuff / ask-introduction.pod You can use utf8 to signal to perl that your file is written in utf8, so you don't have to decode("utf8" all over the place Also see Win32::Unicode::Native since I assume you're on win32 ... for unicode version of mkdir/open... so you don't have to encode("iso-8859-1" ... Also, if you still need to encode("iso-8859-1" .... don't do it all over the place (repetition hurts your fingers), do it in one helper subroutine, say in recup_fic or MyMkdir ... I would also consider my $answer = YesNo( "question", "title" ); and ReadThis( $msg, $title ); ... although Info( $msg, $title ); sounds good .... there is a Ask::Tk, a Ask::Tkx should be only a few tweaks to that | [reply] [d/l] [select] |
by x-lours (Sexton) on Jun 17, 2014 at 13:59 UTC | |
by Anonymous Monk on Jun 18, 2014 at 00:17 UTC | |
by x-lours (Sexton) on Jun 17, 2014 at 14:04 UTC | |
by Anonymous Monk on Jun 13, 2014 at 08:24 UTC | |
While I'm working on some code, take a look at these, I believe they deal with same problem (not enough subs, too many comments, pattern for using threads, que, gui toolkit) ... Re: Win32::GUI window freezing, even with threading. (win32-gui-tk-thread-dequeue.pl, Thread::Queue::popnow/push) + Re^4: Win32::GUI window freezing, even with threading. (Wrong solution), Re: Tk: Creating label in hash, Re: perl Tk thread help, Re: error on file open, Re^4: Query the height of Tk::Text widget with word wrap | [reply] |