markseger has asked for the wisdom of the Perl Monks concerning the following question:
My main script starts a thread that looks for socket connections/disconnections and opens/closes them accordingly and so will never exit. It shares this info with the main program via a shared variable containing the open file numbers. My test program works like a champ and when I exit the main code via a ^C it simply exists.
However, when I take the same code and include it in my real code it works fine there too but when I close that program also with a ^C, I get the infamous "A thread exited while 2 other threads were still running."
This leads to a couple of questions, the most obvious being if I have a thread that never exists, what is the cleanest way to shut down the main script? I suppose I could track down the pid of the thread and kill it from the main script but that feels like it may be masking a more serious problem. I also thought I might be able to set some shared variable in the main line that the thread sees to tell it to shut down but that doesn't feel right either. The thread is also sitting in a can_read() call and so wouldn't see the shared variable anyways.
I'm also puzzled by my simple test script didn't have this problem.
thoughts?
-mark
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Exiting a script with an 'infinitely looping' thread
by BrowserUk (Patriarch) on Nov 24, 2008 at 14:17 UTC | |
by markseger (Beadle) on Nov 24, 2008 at 15:00 UTC | |
by BrowserUk (Patriarch) on Nov 24, 2008 at 15:07 UTC | |
by markseger (Beadle) on Nov 24, 2008 at 15:15 UTC | |
by BrowserUk (Patriarch) on Nov 24, 2008 at 15:27 UTC | |
| |
by ikegami (Patriarch) on Nov 24, 2008 at 16:12 UTC | |
Re: Exiting a script with an 'infinitely looping' thread
by ikegami (Patriarch) on Nov 24, 2008 at 14:05 UTC |