possible bug?
Jeff Epler
jepler at unpythonic.net
Tue Mar 22 16:31:01 EST 2005
On Tue, Mar 22, 2005 at 02:19:52PM -0700, Earl Eiland wrote:
> Well, your program ran successfully. Perhaps WinRK is not well
> behaved. How can a process terminate in such a way that poll() can read
> it, but wait() won't?
I don't have any idea. Both are implemented in terms of
win32event.WaitForSingleObject (which is itself a thin wrapper over the
win32 API of the same name[1]), one with a zero timeout and one with an
INFINITE timeout.
This caveat is in the msdn page on WFSO:
Use caution when calling the wait functions and code that directly
or indirectly creates windows. If a thread creates any windows, it
must process messages. Message broadcasts are sent to all windows in
the system. A thread that uses a wait function with no time-out
interval may cause the system to become deadlocked. Two examples of
code that indirectly creates windows are DDE and the CoInitialize
function. Therefore, if you have a thread that creates windows, use
MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather
than WaitForSingleObject.
... which is pretty much greek to this unix geek. If your Python
program has a GUI, can you strip out the gui-related parts to make it a
pure commandline program, and see if you still have the problem?
You could try something like (untested, obviously)
import subprocess
if subprocess.mswindows:
from win32event import WaitForSingleObject
from win32process import GetExitCodeProcess
def wait(self):
"""Wait for child process to terminate. Returns returncode
attribute."""
while self.returncode is None:
obj = WaitForSingleObject(self._handle, 1000)
self.returncode = GetExitCodeProcess(self._handle)
_active.remove(self)
return self.returncode
subprocess.Popen.wait = wait
to make the .wait() method call WFSO with a timeout, and then maybe you
can simply forget about the weird behavior you ran into.
Jeff
[1] http://msdn.microsoft.com/library/en-us/dllproc/base/waitforsingleobject.asp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050322/5ffb4910/attachment.sig>
More information about the Python-list
mailing list