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: