diff --git a/Lib/test/_test_eintr.py b/Lib/test/_test_eintr.py index 15586f15dfab307..16f29473df2a73e 100644 --- a/Lib/test/_test_eintr.py +++ b/Lib/test/_test_eintr.py @@ -506,7 +506,9 @@ def _lock(self, lock_func, lock_name): with open(os_helper.TESTFN, 'wb') as f: # synchronize the subprocess start_time = time.monotonic() - for _ in support.sleeping_retry(support.LONG_TIMEOUT, error=False): + # make sure to sleep significantly less than sleep_time + # between tries, to minimize the race with the subprocess + for _ in support.sleeping_retry(support.LONG_TIMEOUT, error=False, max_delay=self.sleep_time / 2): try: lock_func(f, fcntl.LOCK_EX | fcntl.LOCK_NB) lock_func(f, fcntl.LOCK_UN)