Add test.support.busy_retry() (#93770)

Add busy_retry() and sleeping_retry() functions to test.support.
This commit is contained in:
Victor Stinner 2022-06-15 11:42:10 +02:00 committed by GitHub
parent 4e9fa71d7e
commit 7e9eaad864
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 186 additions and 99 deletions

View file

@ -2,7 +2,6 @@
"""
import os
import time
import sys
import unittest
from test.fork_wait import ForkWait
@ -22,14 +21,12 @@ class Wait4Test(ForkWait):
# Issue #11185: wait4 is broken on AIX and will always return 0
# with WNOHANG.
option = 0
deadline = time.monotonic() + support.SHORT_TIMEOUT
while time.monotonic() <= deadline:
for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
# wait4() shouldn't hang, but some of the buildbots seem to hang
# in the forking tests. This is an attempt to fix the problem.
spid, status, rusage = os.wait4(cpid, option)
if spid == cpid:
break
time.sleep(0.1)
self.assertEqual(spid, cpid)
self.assertEqual(os.waitstatus_to_exitcode(status), exitcode)
self.assertTrue(rusage)