Commit b05ee3d2 authored by Jason Madden's avatar Jason Madden

Make waitpid(-1) work properly with exited children.

parent 3a265faf
......@@ -238,8 +238,18 @@ if hasattr(os, 'fork'):
"""
# XXX Does not handle tracing children
if pid <= 0:
# magic functions for multiple children. Pass.
return _waitpid(pid, options)
# magic functions for multiple children.
if pid == -1:
# Any child. If we have one that we're watching and that finished,
# we need to use that one. Otherwise, let the OS take care of it.
for k, v in _watched_children.items():
if isinstance(v, tuple):
pid = k
break
if pid <= 0:
# If we didn't find anything, go to the OS. Otherwise,
# handle waiting
return _waitpid(pid, options)
if pid in _watched_children:
# yes, we're watching it
......
import errno
import os
import sys
#os.environ['GEVENT_NOWAITPID'] = 'True'
......@@ -34,6 +35,15 @@ if hasattr(signal, 'SIGCHLD'):
with gevent.Timeout(1):
while awaiting_child:
gevent.sleep(0.01)
# We should now be able to waitpid() for an arbitrary child
wpid, status = os.waitpid(-1, os.WNOHANG)
assert wpid == pid
# And a second call should raise ECHILD
try:
wpid, status = os.waitpid(-1, os.WNOHANG)
raise AssertionError("Should not be able to wait again")
except OSError as e:
assert e.errno == errno.ECHILD
sys.exit(0)
else:
print("No SIGCHLD, not testing")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment