Skip to content

Commit 46e4d0b

Browse files
avian2gaborbernat
andauthored
Use time.monotonic() for calculating timeouts. (#136)
Co-authored-by: Bernát Gábor <[email protected]>
1 parent 9ca0f61 commit 46e4d0b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
v3.5.1 (2022-02-16)
5+
-------------------
6+
- Use ``time.monotonic`` instead of ``time.time`` for calculating timeouts.
7+
48
v3.5.0 (2022-02-15)
59
-------------------
610
- Enable use as context decorator

src/filelock/_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def acquire(
161161

162162
lock_id = id(self)
163163
lock_filename = self._lock_file
164-
start_time = time.time()
164+
start_time = time.monotonic()
165165
try:
166166
while True:
167167
with self._thread_lock:
@@ -172,7 +172,7 @@ def acquire(
172172
if self.is_locked:
173173
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
174174
break
175-
elif 0 <= timeout < time.time() - start_time:
175+
elif 0 <= timeout < time.monotonic() - start_time:
176176
_LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename)
177177
raise Timeout(self._lock_file)
178178
else:

0 commit comments

Comments
 (0)