in reply to Re: Perl5.8.4 , threads - Killing the "async" kid
in thread Perl5.8.4 , threads - Killing the "async" kid
1.BrowserUK wrote:
However--and this is my recommendation--based on the pseudo-code you've posted which suggests the threads in question have no clean up to perform, nor any values to return, I would suggest upgrading to (the binary compatible) 5.8.9 and detaching the threads.
Well, I am to blame here. The pseudo-code, as expected, did not reveal much. This code below is declared before any thread is defined at the very top of the program. In effect, what I have done is to declare redirects for STDOUT and STDERR to a log file. And this is shared by all threads.
# Opening log file. # Redirecting OUTPUT and ERR to log file for all threads open OUTPUT, '>>', "/usr/local/xxx/log/lease.log" or die $!; open ERROR, '>>', "/usr/local/xxx/log/lease.log" or die $!; STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!; STDERR->fdopen( \*ERROR, 'w' ) or die $!;
This simplifies my logging process but it, in turn creates problems when I shut the daemon down. Please keep in mind the the signal handler itself is shared by all threads which means each process has it's signal handlers defined. So what I needed to write in the signal handler was a clean closing of threads and file-handles, independent of the active thread. I thought about something similar to $timetoExit before posting here but did not know how to get beyond that point. The sleep 1 and next while --$sleepTime; was what I was looking for. Saw it. Loved it. Tested it with a mild tweak. And no more error messages.
2.BrowserUK wrote:
Detached threads are, by definition, fire-and-forget, so the earlier warnings were just wrong.
I did try detaching the thread. But the error message kept coming. And I was also worried about the open file handles in the async thread. I kept imagining the main thread receiving a SIGTERM while the sync thread was trying to write to the file-handle. I believe this is a possibility.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl5.8.4 , threads - Killing the "async" kid
by BrowserUk (Patriarch) on Oct 12, 2010 at 12:21 UTC | |
by MonkeyMonk (Sexton) on Oct 12, 2010 at 13:18 UTC | |
by BrowserUk (Patriarch) on Oct 12, 2010 at 13:42 UTC | |
by MonkeyMonk (Sexton) on Oct 14, 2010 at 14:52 UTC | |
by BrowserUk (Patriarch) on Oct 14, 2010 at 15:18 UTC | |
by MonkeyMonk (Sexton) on Oct 13, 2010 at 15:13 UTC | |
by BrowserUk (Patriarch) on Oct 13, 2010 at 15:27 UTC | |
by MonkeyMonk (Sexton) on Oct 13, 2010 at 16:06 UTC | |
by BrowserUk (Patriarch) on Oct 13, 2010 at 16:19 UTC |