Skip to content

Fix ValueError in _acquire_transaction_lock when blocking=False with timeout#498

Merged
gaborbernat merged 2 commits into
mainfrom
fix/transaction-lock-nonblocking-timeout
Feb 23, 2026
Merged

Fix ValueError in _acquire_transaction_lock when blocking=False with timeout#498
gaborbernat merged 2 commits into
mainfrom
fix/transaction-lock-nonblocking-timeout

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

Fix from #497 by @bysiber with added test and lint fixes.

ReadWriteLock._acquire_transaction_lock() crashes with ValueError when called with blocking=False and a non-default timeout.

Python's threading.Lock.acquire() raises ValueError: can't specify a timeout for a non-blocking call when both blocking=False and a timeout are provided. The current code only special-cases timeout == -1, so any other timeout value combined with blocking=False hits this error:

from filelock import ReadWriteLock

lock = ReadWriteLock("test.db")
lock.acquire_read(timeout=5, blocking=False)
# ValueError: can't specify a timeout for a non-blocking call

The fix handles blocking=False as a separate branch that never passes a timeout argument, since a timeout is meaningless for non-blocking acquisition anyway.

bysiber and others added 2 commits February 20, 2026 16:13
…timeout

threading.Lock.acquire() raises ValueError when called with
blocking=False and a timeout argument, since Python does not allow
specifying a timeout for a non-blocking call.

Handle blocking=False as a separate branch that never passes a
timeout, regardless of the timeout parameter value.
@gaborbernat gaborbernat force-pushed the fix/transaction-lock-nonblocking-timeout branch from 1a4ffa8 to d6851c5 Compare February 23, 2026 13:30
@gaborbernat gaborbernat enabled auto-merge (squash) February 23, 2026 13:30
@gaborbernat gaborbernat merged commit 721b37b into main Feb 23, 2026
62 of 63 checks passed
@gaborbernat gaborbernat deleted the fix/transaction-lock-nonblocking-timeout branch February 23, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants