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.perf_counter instead of time.monotonic #194

Merged
merged 5 commits into from Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changelog.rst
@@ -1,5 +1,9 @@
Changelog
=========
in progress
zpz marked this conversation as resolved.
Show resolved Hide resolved
-----------
- Use ``time.perf_counter`` instead of ``time.monotonic`` for calculating timeouts.

v3.9.0 (2022-12-28)
-------------------
- Move build backend to ``hatchling`` :pr:`185 - by :user:`gaborbernat`.
Expand Down
4 changes: 2 additions & 2 deletions src/filelock/_api.py
Expand Up @@ -164,7 +164,7 @@ def acquire(

lock_id = id(self)
lock_filename = self._lock_file
start_time = time.monotonic()
start_time = time.perf_counter() # noqa: SC200
zpz marked this conversation as resolved.
Show resolved Hide resolved
try:
while True:
with self._thread_lock:
Expand All @@ -178,7 +178,7 @@ def acquire(
elif blocking is False:
_LOGGER.debug("Failed to immediately acquire lock %s on %s", lock_id, lock_filename)
raise Timeout(self._lock_file)
elif 0 <= timeout < time.monotonic() - start_time:
elif 0 <= timeout < time.perf_counter() - start_time: # noqa: SC200
_LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename)
raise Timeout(self._lock_file)
else:
Expand Down