Module Expr Str ImportFrom alias Import alias Import alias Import alias Import alias Import alias If UnaryOpNot Call NameLoad NameLoad Str body Assign AttributeStore NameLoad attr AttributeLoad NameLoad attr If UnaryOpNot Call NameLoad AttributeLoad NameLoad attr Str body Assign AttributeStore AttributeLoad NameLoad attr attr AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore ListLoad Str Str Str Str Str Str Str Str Str Str Str Str Str ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body Expr Str Pass decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str Raise Call NameLoad Str decorator_list FunctionDef arguments args NameParam defaults body Expr Str Raise Call NameLoad Str decorator_list FunctionDef arguments args NameParam defaults body Expr Str Expr Call AttributeLoad NameLoad attr Return NameLoad decorator_list FunctionDef arguments args NameParam defaults vararg body Expr Str Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str TupleLoad AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults NameLoad NameLoad body Expr Str Expr Call AttributeLoad Call NameLoad NameLoad NameLoad attr NameLoad Assign AttributeStore NameLoad attr BinOpAdd Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad Str Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr If NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call NameLoad NameLoad Str Call NameLoad NameLoad Assign AttributeStore NameLoad attr BinOpMod Str BinOpBitAnd NameLoad Num orelse Assign AttributeStore NameLoad attr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Raise Call NameLoad Str decorator_list FunctionDef arguments args NameParam defaults body Expr Str Raise Call NameLoad Str decorator_list FunctionDef arguments args NameParam defaults body Expr Str Raise Call NameLoad Str decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str TupleLoad AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list decorator_list FunctionDef arguments args NameParam NameParam defaults vararg kwarg body Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad NameLoad keyword Num If UnaryOpNot Call NameLoad SubscriptLoad NameLoad Index Num NameLoad body Assign NameStore SubscriptLoad NameLoad Slice Num If BoolOpAnd CompareEq Call NameLoad NameLoad Num UnaryOpNot NameLoad body Assign SubscriptStore NameLoad Index Str NameLoad Return Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args defaults vararg kwarg body Expr Str ImportFrom alias Return Call NameLoad AttributeLoad NameLoad attr Str NameLoad NameLoad decorator_list FunctionDef arguments args defaults vararg kwarg body Expr Str ImportFrom alias Return Call NameLoad AttributeLoad NameLoad attr Str NameLoad NameLoad decorator_list FunctionDef arguments args defaults vararg kwarg body Expr Str ImportFrom alias Return Call NameLoad AttributeLoad NameLoad attr Str NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str FunctionDef arguments args NameParam defaults body FunctionDef arguments args defaults vararg kwarg body Assign NameStore Call NameLoad NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr TryFinally body Return Call NameLoad NameLoad NameLoad finalbody Expr Call AttributeLoad NameLoad attr decorator_list Call AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list Return NameLoad decorator_list If Call NameLoad NameLoad Str body ImportFrom alias identifier Assign NameStore AttributeLoad NameLoad attr orelse ImportFrom alias identifier Assign NameStore AttributeLoad NameLoad attr Assign NameStore NameLoad
N/A N/A 
lockfile.py - Platform-independent advisory file locks.

Requires Python 2.5 unless you apply 2.4.diff
Locking is done on a per-thread basis instead of a per-process basis.

Usage:

>>> lock = LockFile('somefile')
>>> try:
...     lock.acquire()
... except AlreadyLocked:
...     print 'somefile', 'is locked already.'
... except LockFailed:
...     print 'somefile', 'can\'t be locked.'
... else:
...     print 'got lock'
got lock
>>> print lock.is_locked()
True
>>> lock.release()

>>> lock = LockFile('somefile')
>>> print lock.is_locked()
False
>>> with lock:
...    print lock.is_locked()
True
>>> print lock.is_locked()
False

>>> lock = LockFile('somefile')
>>> # It is okay to lock twice from the same thread...
>>> with lock:
...     lock.acquire()
...
>>> # Though no counter is kept, so you can't unlock multiple times...
>>> print lock.is_locked()
False

Exceptions:

    Error - base class for other exceptions
        LockError - base class for all locking exceptions
            AlreadyLocked - Another thread or process already holds the lock
            LockFailed - Lock failed for some other reason
        UnlockError - base class for all unlocking exceptions
            AlreadyUnlocked - File was not locked.
            NotMyLock - File was locked but not by the current thread/process
 __future__ absolute_import N/A functools N/A os N/A socket N/A threading N/A warnings N/A N/A N/A hasattr threading current_thread N/A N/A N/A threading current_thread N/A threading currentThread N/A N/A N/A hasattr N/A threading Thread get_name N/A N/A N/A N/A threading Thread get_name N/A N/A threading Thread getName N/A __all__ N/A Error LockError LockTimeout AlreadyLocked LockFailed UnlockError NotLocked NotMyLock LinkFileLock MkdirFileLock SQLiteFileLock LockBase locked Error N/A Exception N/A N/A 
    Base class for other exceptions.

    >>> try:
    ...   raise Error
    ... except Exception:
    ...   pass
     N/A N/A LockError N/A Error N/A N/A 
    Base class for error arising from attempts to acquire the lock.

    >>> try:
    ...   raise LockError
    ... except Error:
    ...   pass
     N/A N/A LockTimeout N/A LockError N/A N/A Raised when lock creation fails within a user-defined period of time.

    >>> try:
    ...   raise LockTimeout
    ... except LockError:
    ...   pass
     N/A N/A AlreadyLocked N/A LockError N/A N/A Some other thread/process is locking the file.

    >>> try:
    ...   raise AlreadyLocked
    ... except LockError:
    ...   pass
     N/A N/A LockFailed N/A LockError N/A N/A Lock file creation failed for some other reason.

    >>> try:
    ...   raise LockFailed
    ... except LockError:
    ...   pass
     N/A N/A UnlockError N/A Error N/A N/A 
    Base class for errors arising from attempts to release the lock.

    >>> try:
    ...   raise UnlockError
    ... except Error:
    ...   pass
     N/A N/A NotLocked N/A UnlockError N/A N/A Raised when an attempt is made to unlock an unlocked file.

    >>> try:
    ...   raise NotLocked
    ... except UnlockError:
    ...   pass
     N/A N/A NotMyLock N/A UnlockError N/A N/A Raised when an attempt is made to unlock a file someone else locked.

    >>> try:
    ...   raise NotMyLock
    ... except UnlockError:
    ...   pass
     N/A N/A _SharedBase N/A object N/A __init__ N/A N/A self path N/A N/A N/A N/A self path path N/A acquire N/A N/A self timeout N/A None N/A N/A 
        Acquire the lock.

        * If timeout is omitted (or None), wait forever trying to lock the
          file.

        * If timeout > 0, try to acquire the lock for that many seconds.  If
          the lock period expires and the file is still locked, raise
          LockTimeout.

        * If timeout <= 0, raise AlreadyLocked immediately if the file is
          already locked.
         N/A N/A NotImplemented implement in subclass N/A release N/A N/A self N/A N/A N/A 
        Release the lock.

        If the file is not locked, raise NotLocked.
         N/A N/A NotImplemented implement in subclass N/A __enter__ N/A N/A self N/A N/A N/A 
        Context manager support.
         N/A N/A N/A self acquire N/A self N/A __exit__ N/A N/A self N/A _exc N/A N/A 
        Context manager support.
         N/A N/A N/A self release N/A __repr__ N/A N/A self N/A N/A N/A N/A <%s: %r> N/A N/A N/A self __class__ __name__ N/A self path N/A N/A LockBase N/A _SharedBase N/A N/A Base class for platform-specific lock classes. __init__ N/A N/A self path threaded timeout N/A True None N/A N/A 
        >>> lock = LockBase('somefile')
        >>> lock = LockBase('somefile', threaded=False)
         N/A N/A N/A N/A super LockBase self __init__ path N/A N/A self lock_file N/A N/A N/A N/A os path abspath path .lock N/A N/A self hostname N/A N/A socket gethostname N/A N/A self pid N/A N/A os getpid N/A threaded N/A N/A t N/A N/A threading current_thread N/A ident N/A getattr t ident N/A hash t N/A N/A self tname N/A -%x N/A ident 4294967295 N/A N/A N/A self tname N/A dirname N/A N/A N/A os path dirname N/A self lock_file N/A N/A self unique_name N/A N/A N/A os path join dirname N/A %s%s.%s%s N/A N/A self hostname N/A self tname N/A self pid N/A hash N/A self path N/A N/A self timeout timeout N/A is_locked N/A N/A self N/A N/A N/A 
        Tell whether or not the file is locked.
         N/A N/A NotImplemented implement in subclass N/A i_am_locking N/A N/A self N/A N/A N/A 
        Return True if this object is locking the file.
         N/A N/A NotImplemented implement in subclass N/A break_lock N/A N/A self N/A N/A N/A 
        Remove a lock.  Useful if a locking thread failed to unlock.
         N/A N/A NotImplemented implement in subclass N/A __repr__ N/A N/A self N/A N/A N/A N/A <%s: %r -- %r> N/A N/A N/A self __class__ __name__ N/A self unique_name N/A self path N/A N/A _fl_helper N/A N/A cls mod N/A args kwds N/A N/A N/A N/A warnings warn N/A Import from %s module instead of lockfile package mod DeprecationWarning stacklevel 2 N/A N/A N/A isinstance N/A args N/A 0 str N/A N/A args N/A args N/A 1 N/A N/A N/A N/A len args 1 N/A kwds N/A N/A N/A kwds N/A threaded True N/A N/A cls args kwds N/A LinkFileLock N/A N/A N/A args kwds N/A N/A Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import LinkLockFile from the
    lockfile.linklockfile module.
     N/A linklockfile N/A N/A _fl_helper N/A linklockfile LinkLockFile lockfile.linklockfile args kwds N/A MkdirFileLock N/A N/A N/A args kwds N/A N/A Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import MkdirLockFile from the
    lockfile.mkdirlockfile module.
     N/A mkdirlockfile N/A N/A _fl_helper N/A mkdirlockfile MkdirLockFile lockfile.mkdirlockfile args kwds N/A SQLiteFileLock N/A N/A N/A args kwds N/A N/A Factory function provided for backwards compatibility.

    Do not use in new code.  Instead, import SQLiteLockFile from the
    lockfile.mkdirlockfile module.
     N/A sqlitelockfile N/A N/A _fl_helper N/A sqlitelockfile SQLiteLockFile lockfile.sqlitelockfile args kwds N/A locked N/A N/A path timeout N/A None N/A N/A Decorator which enables locks for decorated function.

    Arguments:
     - path: path for lockfile.
     - timeout (optional): Timeout for acquiring lock.

     Usage:
         @locked('/var/run/myname', timeout=0)
         def myname(...):
             ...
     decor N/A N/A func N/A N/A wrapper N/A N/A N/A args kwargs N/A N/A lock N/A FileLock path timeout timeout N/A N/A N/A lock acquire N/A N/A N/A N/A func args kwargs N/A N/A N/A N/A lock release N/A N/A N/A functools wraps func N/A wrapper N/A N/A decor N/A N/A N/A hasattr os link N/A N/A linklockfile _llf N/A LockFile N/A _llf LinkLockFile N/A N/A mkdirlockfile _mlf N/A LockFile N/A _mlf MkdirLockFile N/A FileLock LockFile