LockFile.acquire() argument docs are incorrect
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pylockfile |
Fix Released
|
Medium
|
Davanum Srinivas (DIMS) |
Bug Description
According to http://
> If the timeout is zero or a negative number the AlreadyLocked exception will be raised if the file is currently locked by another process or thread.
I have two Python shells open. In one, I've run:
>>> import lockfile
>>> a = lockfile.
>>> a.acquire()
In the other, I run:
>>> import lockfile
>>> a = lockfile.
>>> a.acquire(0) # Hangs until I ctrl-C interrupt it
>>> a.acquire(-1)
Traceback (most recent call last):
[...]
lockfile.
The docs incorrectly state that a.acquire(0) and a.acquire(-1) should have the same behavior.
Changed in pylockfile: | |
status: | New → Confirmed |
importance: | Undecided → Medium |
tags: | added: small |
Changed in pylockfile: | |
assignee: | nobody → Davanum Srinivas (DIMS) (dims-v) |
status: | Confirmed → In Progress |
Changed in pylockfile: | |
milestone: | none → 0.11.0 |
status: | Fix Committed → Fix Released |
I just opened https:/ /bugs.launchpad .net/pylockfile /+bug/1468124 before I realized it was more or less a duplicate of this issue.
I would add that this was noted and the current code looks like an attempt to fix the bug:
>>> % git show 58c3832d --pretty=full linklockfile. py b/lockfile/ linklockfile. py linklockfile. py linklockfile. py LockBase) :
>>> commit 58c3832
>>> Author: Skip Montanaro <email address hidden>
>>> Commit: Skip Montanaro <email address hidden>
>>>
>>> fix for timeout=0
>>>
>>> diff --git a/lockfile/
>>> index a906568..9c50673 100644
>>> --- a/lockfile/
>>> +++ b/lockfile/
>>> @@ -19,7 +19,7 @@ class LinkLockFile(
>>> except IOError:
>>> raise LockFailed("failed to create %s" % self.unique_name)
>>>
>>> - timeout = timeout or self.timeout
>>> + timeout = timeout is not None and timeout or self.timeout
>>> end_time = time.time()
>>> if timeout is not None and timeout > 0:
>>> end_time += timeout
>>> *SNIP*
I'd also mention that this is a regression introduced by ecd17a7, and so it would probably be better to fix the code than the docs.