summaryrefslogtreecommitdiffstats
path: root/Lib/test/support/__init__.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-15 12:09:56 (GMT)
committerGitHub <noreply@github.com>2022-06-15 12:09:56 (GMT)
commit0ba80273f2dba5b70de870a333e65ad025cca640 (patch)
tree7f21af5a00c17463625072031650af5bd50895ea /Lib/test/support/__init__.py
parentbddbd80cff950b16712ae9e72eeba2a0f26c65e0 (diff)
downloadcpython-0ba80273f2dba5b70de870a333e65ad025cca640.zip
cpython-0ba80273f2dba5b70de870a333e65ad025cca640.tar.gz
cpython-0ba80273f2dba5b70de870a333e65ad025cca640.tar.bz2
Use support.sleeping_retry() and support.busy_retry() (#93848)
* Replace time.sleep(0.010) with sleeping_retry() to use an exponential sleep. * support.wait_process(): reuse sleeping_retry(). * _test_eintr: remove unused variables.
Diffstat (limited to 'Lib/test/support/__init__.py')
-rw-r--r--Lib/test/support/__init__.py35
1 files changed, 15 insertions, 20 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index a62e8b4..a875548 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2072,31 +2072,26 @@ def wait_process(pid, *, exitcode, timeout=None):
if timeout is None:
timeout = SHORT_TIMEOUT
- t0 = time.monotonic()
- sleep = 0.001
- max_sleep = 0.1
- while True:
+
+ start_time = time.monotonic()
+ for _ in sleeping_retry(timeout, error=False):
pid2, status = os.waitpid(pid, os.WNOHANG)
if pid2 != 0:
break
- # process is still running
-
- dt = time.monotonic() - t0
- if dt > SHORT_TIMEOUT:
- try:
- os.kill(pid, signal.SIGKILL)
- os.waitpid(pid, 0)
- except OSError:
- # Ignore errors like ChildProcessError or PermissionError
- pass
-
- raise AssertionError(f"process {pid} is still running "
- f"after {dt:.1f} seconds")
+ # rety: the process is still running
+ else:
+ try:
+ os.kill(pid, signal.SIGKILL)
+ os.waitpid(pid, 0)
+ except OSError:
+ # Ignore errors like ChildProcessError or PermissionError
+ pass
- sleep = min(sleep * 2, max_sleep)
- time.sleep(sleep)
+ dt = time.monotonic() - start_time
+ raise AssertionError(f"process {pid} is still running "
+ f"after {dt:.1f} seconds")
else:
- # Windows implementation
+ # Windows implementation: don't support timeout :-(
pid2, status = os.waitpid(pid, 0)
exitcode2 = os.waitstatus_to_exitcode(status)