Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
I have a multi-threaded perl script that runs on windows. It uses threads and Threads::Queue modules, child threads get the work from queue and work on it. But sometime the script get stuck at some times and I have no clue what it is waiting for or why it is stuck. But when I give some interrrupt signal ctrl + z, it resumes the process.. I dont know what causes that..
How I can monitor the work of a thread?
How can I get the exception thrown from a thread? Thanks!
use threads ('exit' => 'threads_only'); use Thread::Queue; #create child threads my $childs = 2; my $Q = new Thread::Queue; my @kids = map threads->create(\&processData, $Q), 1 .. $childs # this is how queue work for the processData() once I get some work to + do $Q->enqueue($work); sleep 1 while $Q_->pending > $childs; ### How I can check for any errors in a thread here? #Join all the child threads once every work is done $_->join for @kids;

Replies are listed 'Best First'.
Re: Threaded Perl script not responding
by BrowserUk (Patriarch) on Aug 15, 2011 at 20:41 UTC

    It is impossible to debug your non-running code snippet.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Threaded Perl script not responding
by zentara (Cardinal) on Aug 16, 2011 at 11:46 UTC
    But when I give some interrrupt signal ctrl + z, it resumes the process.. I dont know what causes that..

    It sounds like your threads are hanging on something and waiting for input to proceed. Have you noticed that other key presses work too? Like maybe just hitting Enter a few times? Are you running a socket or database access in the threads? Threads can hang on a screwed up IO operation.

    How I can check for any errors in a thread here?

    With the limited code you show, it's only a suggestion, but sprinkle your \&processData subroutine with as many debugging printouts as you can, and see where it hangs and requires your cntrl z.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Are you running a socket or database access in the threads? Threads can hang on a screwed up IO operation.

      I am using database access inside the thread and a lot of I/O operation. How can I refresh the thread or do some kind of check to make sure the threads are active. I just do not understand an interrupt signal just resumes the threads to go active again?