CreateProcess handle immediatly signaled

David Bolen db3l at fitlinxx.com
Wed Aug 16 17:37:01 EDT 2000


Dale Burnett <denalione at my-deja.com> writes:

> After further invetigation I have discovered that I just dont know what
> Im doing.  The child process spawns secondary threads then the main
> thread exits.  It appears that when the main thread exits the secondary
> threads exit automatically, while I thought the secondary threads would
> continue to keep the process running and the process would stay non
> signaled.
> 
> If anyone knows if that is right or wrong please let me know.

Your prior post was about running python as the child process, so are
the threads you're talking about in the Python executable itself or
done within the Python script (say with the threading module).  By
default the threading module will wait for all non-daemon threads to
exit if the main thread tries to exit.

In terms of the raw Win32 process handling, while the thread object
handle from CreateProcess could become signaled if such an operation
takes place (the thread object handle you get back from CreateProcess
is for the primary thread), the process handle object itself won't
signal until the entire process has completed.

For thread/process exiting, yes, if you just permit your main thread
in a C/C++ application to exit/return, then it'll shut down your
entire process even if other threads are running.  This is more an
artifact (I believe) of the C RTL and not Win32 itself.  If you want
to exit the main thread only but leave any other running threads, you
can call _exitthread() (or ExitThread if you're not using the C RTL
thread support) in the main thread rather than letting it return
normally or call exit().

For what it's worth, I just ran a quick test with Python running a
script that just delayed a bit (both in a primary and secondary
thread), and I don't have any problem waiting on the process object
until the script actually completes.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list