lockfile.acquire doesn't accept a timeout of 0

Bug #1468124 reported by Michael Komitee
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pylockfile
Fix Released
Undecided
Davanum Srinivas (DIMS)

Bug Description

The documentation for lockfile.acquire (http://pythonhosted.org/lockfile/lockfile.html#lockfile.LockFile.acquire):

    LockFile.acquire(timeout=None)

    Lock the file associated with the LockFile object. If the timeout is omitted or None the caller will block until the file is unlocked by the object currently holding the lock. 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. If the timeout is positive, the caller will block for that many seconds waiting for the lock to be released. If the lock is not released within that period the LockTimeout exception will be raised.

Indicates that lock.acquire(timeout=0) would not block, but it does (for linklockfile) because 0 is not truthy, and the line:

        timeout = timeout is not None and timeout or self.timeout

when timeout is 0 causes it to default to self.timeout, which by default is None.

Either 0 should be special cased so that the documentation is correct (preferable because users may already expect that to work) or the documentation needs to be updated to indicate a negative number is the only way to indicate that acquire shouldn't block.

Thanks.

Revision history for this message
Michael Komitee (mkomitee) wrote :

Now that I see all of the open issues, I can see that this is effectively a duplicate of https://bugs.launchpad.net/pylockfile/+bug/1419127.

Changed in pylockfile:
assignee: nobody → Davanum Srinivas (DIMS) (dims-v)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to pylockfile (master)

Reviewed: https://review.openstack.org/221100
Committed: https://git.openstack.org/cgit/openstack/pylockfile/commit/?id=333cbd39a50e5908136f9270a354ff5d1f6b6956
Submitter: Jenkins
Branch: master

commit 333cbd39a50e5908136f9270a354ff5d1f6b6956
Author: Davanum Srinivas <email address hidden>
Date: Mon Sep 7 16:05:56 2015 -0400

    lockfile.acquire doesn't accept a timeout of 0

    Docs indicates that lock.acquire(timeout=0) would not block, but it
    does (for linklockfile) because 0 is not truthy, and the line:

       timeout = timeout is not None and timeout or self.timeout

    when timeout is 0 causes it to default to self.timeout, which by default is None.

    So rewrite the condition better to take into account that timeout may
    be set to 0.

    Closes-Bug: #1468124
    Closes-Bug: #1419127
    Change-Id: Idf0d00977e79661e1eafd695d6e148e5f27e1840

Changed in pylockfile:
status: In Progress → Fix Committed
Revision history for this message
Michael Komitee (mkomitee) wrote :

Thanks for getting to this.

Changed in pylockfile:
milestone: none → 0.11.0
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.