From ba0462e4012205d639dfdc9e13fb66c2afef6f3b Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Sat, 8 Oct 2016 19:26:32 -0700 Subject: Added safe_sleep() --- test/util.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/util.py b/test/util.py index e8bb9c2..9c379f0 100644 --- a/test/util.py +++ b/test/util.py @@ -38,6 +38,20 @@ def umount(mount_process, mnt_dir): pytest.fail('mount process did not terminate') +def safe_sleep(secs): + '''Like time.sleep(), but sleep for at least *secs* + + `time.sleep` may sleep less than the given period if a signal is + received. This function ensures that we sleep for at least the + desired time. + ''' + + now = time.time() + end = now + secs + while now < end: + time.sleep(end - now) + now = time.time() + # If valgrind and libtool are available, use them def has_program(name): try: -- cgit v1.2.3