On the basis of what you've said, it seems likely that the problem arises because you are using IPC::Open2 in conjunction with threads. IPC::Open2 "forks" the command to be processed. Under Win32, fork is implemented under the covers using a pseudo-process--which is a thread!
It seems likely that if you are sure that all your threads are ending cleanly, that the extra thread is that created under the covers by the call to open2().
A few possibilities come to mind, but are untested.
The 'pid' returned from open2() is actually a thread id. Use $threadObj = threads->object( $pid ); to obtain a handle to that thread and then either:
prior to exiting the program.
Or, if your code is otherwise working correctly except for the exit time warning, accept it is just a warning and ignore it.
Other possibilities that might work, but without more information (code to look at and try) are just speculation, include:
Really, the first thing you need to determine is whether the extra running thread is one you have created or one started by open2. The best way to determine that is by using something like ProcessExplorer to determine what threads are still running when the program s about to exit. ProcessExplorer allows you to view the process and examine the threads including their system-assigned thread IDs (which are different from those used by the threads!).
The problem here is that there are four identifiers for every Perl created thread:
threads has a private method:_handle() which will give you the system assigned thread handle associated with a given (or current) Perl threads object. However, the identifier in ProcessExplorer is the system assigned thread ID. In order to discover which thread is still running at termination, it will be necessary to inspect the process (with ProcessExplorer) and note the thread IDs of the still running threads and relate them to the threads you've started and finished.
The only way I know of doing that is to use the system API GetCurrentThread(), but that will involve using Inline C, or XS, or Win32::API.
If you can determine for sure what thread is still running, then you have a start on working out why that is the case. If you can produce a runnable, cut-down version that demonstrates the problem, I might have a go at trying to come up with a solution.
In reply to Re: cleanly exiting threads
by BrowserUk
in thread cleanly exiting threads
by JoeKamel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |