skip to navigation
skip to content

Not Logged In

flufl.lock 2.2.1

NFS-safe file locking with timeouts for POSIX systems

Package Documentation


NFS-safe file locking with timeouts for POSIX systems

The flufl.lock library provides an NFS-safe file-based locking algorithm influenced by the GNU/Linux open(2) manpage, under the description of the O_EXCL option:

[...] O_EXCL is broken on NFS file systems, programs which rely on it
for performing locking tasks will contain a race condition.  The
solution for performing atomic file locking using a lockfile is to
create a unique file on the same fs (e.g., incorporating hostname and
pid), use link(2) to make a link to the lockfile.  If link() returns
0, the lock is successful.  Otherwise, use stat(2) on the unique file
to check if its link count has increased to 2, in which case the lock
is also successful.

The assumption made here is that there will be no outside interference, e.g. no agent external to this code will ever link() to the specific lock files used.

Lock objects support lock-breaking so that you can't wedge a process forever. This is especially helpful in a web environment, but may not be appropriate for all applications.

Locks have a lifetime, which is the maximum length of time the process expects to retain the lock. It is important to pick a good number here because other processes will not break an existing lock until the expected lifetime has expired. Too long and other processes will hang; too short and you'll end up trampling on existing process locks -- and possibly corrupting data. In a distributed (NFS) environment, you also need to make sure that your clocks are properly synchronized.


This file is part of flufl.lock.

flufl.lock is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3 of the License.

flufl.lock is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with flufl.lock. If not, see <>.

NEWS for flufl.lock

2.2.1 (2012-04-19)

  • Add classifiers to and make the long description more compatible with the Cheeseshop.
  • Other changes to make the Cheeseshop page look nicer. (LP: #680136)
  • version 2.1.

2.2 (2012-01-19)

  • Support Python 3 without the use of 2to3.
  • Make the documentation clear that the flufl.test.subproc functions are not part of the public API. (LP: #838338)
  • Fix claim file format in take_possession(). (LP: #872096)
  • Provide a new API for dealing with possible additional unexpected errnos while trying to read the lock file. These can happen in some NFS environments. If you want to retry the read, set the lock file's retry_errnos property to a sequence of errnos. If one of those errnos occurs, the read is unconditionally (and infinitely) retried. retry_errnos is a property which must be set to a sequence; it has a getter and a deleter too. (LP: #882261)

2.1.1 (2011-08-20)

  • Fixed TypeError in .lock() method due to race condition in _releasetime property. Found by Stephen A. Goss. (LP: #827052)

2.1 (2010-12-22)

  • Added lock.details.

2.0.2 (2010-12-19)

  • Small adjustment to doctest.

2.0.1 (2010-11-27)

  • Add missing exception to __all__.

2.0 (2010-11-26)

  • Package renamed to flufl.lock.


Try bzr log lp:flufl.lock for details.

File Type Py Version Uploaded on Size
flufl.lock-2.2.1.tar.gz (md5, pgp) Source 2012-04-20 23KB
  • Downloads (All Versions):
  • 140 downloads in the last day
  • 663 downloads in the last week
  • 1970 downloads in the last month