From 46e4d0bbb27666118a1655c6d9905a400a15123c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20=C5=A0olc?= Date: Wed, 16 Feb 2022 15:01:37 +0100 Subject: [PATCH] Use time.monotonic() for calculating timeouts. (#136) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bernát Gábor --- docs/changelog.rst | 4 ++++ src/filelock/_api.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 376ec06..4444add 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +v3.5.1 (2022-02-16) +------------------- +- Use ``time.monotonic`` instead of ``time.time`` for calculating timeouts. + v3.5.0 (2022-02-15) ------------------- - Enable use as context decorator diff --git a/src/filelock/_api.py b/src/filelock/_api.py index d3cffc4..282106f 100644 --- a/src/filelock/_api.py +++ b/src/filelock/_api.py @@ -161,7 +161,7 @@ def acquire( lock_id = id(self) lock_filename = self._lock_file - start_time = time.time() + start_time = time.monotonic() try: while True: with self._thread_lock: @@ -172,7 +172,7 @@ def acquire( if self.is_locked: _LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename) break - elif 0 <= timeout < time.time() - start_time: + elif 0 <= timeout < time.monotonic() - start_time: _LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename) raise Timeout(self._lock_file) else: