Skip to content

Commit

Permalink
Use time.monotonic() for calculating timeouts. (#136)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernát Gábor <[email protected]>
  • Loading branch information
avian2 and gaborbernat authored Feb 16, 2022
1 parent 9ca0f61 commit 46e4d0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/filelock/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 46e4d0b

Please sign in to comment.