lockfile 0.1 - platform-independent advisory locks for Python

skip at pobox.com skip at pobox.com
Sat Nov 3 19:09:51 CET 2007

Python's distribution supports a few different ways to lock files.  None are
platform-independent though.  A number of implementations of file locks are
out there, but as an exploration of the possibilities I wrote the lockfile
module.  It offers these features:

    * A platform-independent API
    * Three classes implementing file locks
      - LinkFileLock - relies on atomic nature of the link(2) system call.
      - MkdirFileLock - relies on atomic nature of the mkdir(2) systemm
      - SQLiteFileLock - provides locks through a SQLite database.
    * Locking is done on a per-thread basis by default, though locking can
      be done on a per-process basis instead.
    * Context manager support.

The module contains documentation in ReST format and a decent set of test
cases written using doctest.  Almost all the test cases are attached to the
_FileLock base class, so other implementations (e.g., using different
relational databases or object databases like ZODB) can be sure they satisfy
the same constraints.

The lockfile module is available from PyPI:


I welcome feedback from anyone who gives it a whirl.  The code is stored in
a Mercurial repository on my laptop, so subject to occasional access
problems when I'm on the train others are welcome to have access to the
source code.  If that's of interest to you, drop me a note.

Skip Montanaro - skip at pobox.com - http://www.webfast.com/~skip/

More information about the Python-announce-list mailing list