Commit b2987ba4 authored by Jason Madden's avatar Jason Madden

Make Popen.wait() raise the right exception on PY3 windows so that...

Make Popen.wait() raise the right exception on PY3 windows so that subprocess.call() doesn't hang if the process doesn't exit within the timeout.
parent b6d0eaf6
......@@ -98,6 +98,7 @@ if 'waitpid' in gevent.os.__implements__ and hasattr(_signal, 'SIGCHLD'):
__implements__.append("signal")
__implements__.append("getsignal")
else:
# XXX: This breaks test__all__ on windows
__extensions__.append("signal")
__extensions__.append("getsignal")
......
......@@ -637,6 +637,8 @@ class Popen(object):
self.stdin.close()
finally:
# Wait for the process to terminate, to avoid zombies.
# JAM: gevent: If the process never terminates, this
# blocks forever.
self.wait()
if mswindows:
......@@ -758,8 +760,7 @@ class Popen(object):
"""Execute program (MS Windows version)"""
assert not pass_fds, "pass_fds not supported on Windows."
print("Executing", executable, args, file=sys.stderr)
import traceback; traceback.print_stack()
if not isinstance(args, string_types):
args = list2cmdline(args)
......@@ -847,7 +848,6 @@ class Popen(object):
return self.returncode
def rawlink(self, callback):
print("RAWLINK", callback, file=sys.stderr)
if not self.result.ready() and not self._waiting:
self._waiting = True
Greenlet.spawn(self._wait)
......@@ -855,27 +855,24 @@ class Popen(object):
# XXX unlink
def _blocking_wait(self):
print("BLOCKING WAIT", file=sys.stderr)
WaitForSingleObject(self._handle, INFINITE)
print("DONE BLACKING WAIT", file=sys.stderr)
self.returncode = GetExitCodeProcess(self._handle)
return self.returncode
def _wait(self):
print("RUN _WAIT", file=sys.stderr)
self.threadpool.spawn(self._blocking_wait).rawlink(self.result)
def wait(self, timeout=None):
"""Wait for child process to terminate. Returns returncode
attribute."""
print("RUN WAIT", timeout, "rc", self.returncode, 'waiting', self._waiting, file=sys.stderr)
if self.returncode is None:
if not self._waiting:
self._waiting = True
self._wait()
print("WAIT on result", file=sys.stderr)
return self.result.wait(timeout=timeout)
result = self.result.wait(timeout=timeout)
if PY3 and timeout is not None and not self.result.ready():
raise TimeoutExpired(self.args, timeout)
return result
def send_signal(self, sig):
"""Send a signal to the process
......@@ -892,7 +889,6 @@ class Popen(object):
def terminate(self):
"""Terminates the process
"""
print("TERMINATE", file=sys.stderr)
TerminateProcess(self._handle, 1)
kill = terminate
......
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