From d1ee9a18c8bf48bfe44cf0b8b1d17f3facdf4d8f Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Thu, 24 Feb 2022 23:01:29 -0600 Subject: [PATCH] restrucurte lock file timeout --- pytools/persistent_dict.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pytools/persistent_dict.py b/pytools/persistent_dict.py index 04fbd3e..a42ab63 100644 --- a/pytools/persistent_dict.py +++ b/pytools/persistent_dict.py @@ -114,18 +114,29 @@ class LockManager(CleanupBase): except OSError: pass + # This value was chosen based on the py-filelock package: + # https://github.com/tox-dev/py-filelock/blob/a6c8fabc4192fa7a4ae19b1875ee842ec5eb4f61/src/filelock/_api.py#L113 + wait_time_seconds = 0.05 + + # Warn every 10 seconds if not able to acquire lock + warn_attempts = int(10/wait_time_seconds) + + # Exit after 60 seconds if not able to acquire lock + exit_attempts = int(60/wait_time_seconds) + from time import sleep - sleep(1) + sleep(wait_time_seconds) attempts += 1 - if attempts > 10: + if attempts % warn_attempts == 0: from warnings import warn warn("could not obtain lock -- " f"delete '{self.lock_file}' if necessary", stacklevel=1 + stacklevel) - if attempts > 3 * 60: - raise RuntimeError("waited more than three minutes " + + if attempts > exit_attempts: + raise RuntimeError("waited more than one minute " f"on the lock file '{self.lock_file}' " "-- something is wrong") -- GitLab