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:

  1. The system assigned ThreadID. A system-wide unique non-zero integer.
  2. The system assigned thread handle. An opaque object handle to system internal data structures.
  3. The threads object handle. A Perl assigned blessed reference.
  4. The Perl-assigned, process-unique integer.

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.


  1. 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.

    In reply to Re: cleanly exiting threads by BrowserUk
    in thread cleanly exiting threads by JoeKamel

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  2. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  3. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  4. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  5. Please read these before you post! —
  6. Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  7. You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  8. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  9. See Writeup Formatting Tips and other pages linked from there for more info.