From 95d0d5caa957291fb77d88d910e9801b2062bc02 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 13 Oct 2019 13:38:04 +0200 Subject: [PATCH] clients/tests: shorten sleep while polling in popen_wait() This is basically what cpython's subprocess.wait() does. --- clients/tests/test-client.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/clients/tests/test-client.py b/clients/tests/test-client.py index f42a6d683f..af26756def 100755 --- a/clients/tests/test-client.py +++ b/clients/tests/test-client.py @@ -181,12 +181,18 @@ class Util: except subprocess.TimeoutExpired: return None start = NM.utils_get_timestamp_msec() + delay = 0.0005 while True: if p.poll() is not None: return p.returncode - if timeout == 0 or start + (timeout * 1000) < NM.utils_get_timestamp_msec(): + if timeout == 0: return None - time.sleep(0.05) + assert(timeout > 0) + remaining = timeout - ((NM.utils_get_timestamp_msec() - start) / 1000.0) + if remaining <= 0: + return None + delay = min(delay * 2, remaining, 0.05) + time.sleep(delay) @staticmethod def random_job(jobs):