Commit aaca14e7 authored by André Anjos's avatar André Anjos 💬

[async] Provide a more robust timeout mechanism (works with unittests)

parent 19b23df1
......@@ -31,6 +31,7 @@
import os
import sys
import time
import collections
import distutils.spawn
......@@ -291,7 +292,18 @@ class Popen(gevent.subprocess.Popen):
gevent.spawn(_read_stream, self.stdout, self.__stdout)
gevent.spawn(_read_stream, self.stderr, self.__stderr)
retval = super(Popen, self).wait(timeout)
# in some test cases, timeout may actually expire before the announced
# number of seconds. To avoid errors, we check if we're really supposed to
# expire, otherwise we retry.
if timeout is not None:
timeout = float(timeout)
while timeout > 0.0:
start = time.time()
retval = super(Popen, self).wait(timeout)
if retval is not None: break
timeout -= (time.time() - start)
retval = super(Popen, self).wait(timeout)
if retval is None and timeout is not None:
raise TimeoutExpired(timeout)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment