Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use time.monotonic() for calculating timeouts. #136

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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