lockfile - pydoc - phpman

Look up a command

 

Markdown Format | JSON API | MCP Server Tool


lockfile
NAME DESCRIPTION PACKAGE CONTENTS SUBMODULES CLASSES FUNCTIONS DATA FILE
Help on package lockfile:

NAME
    lockfile - lockfile.py - Platform-independent advisory file locks.

DESCRIPTION
    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
    >>> lock.is_locked()
    True
    >>> lock.release()

    >>> lock = LockFile('somefile')
    >>> lock.is_locked()
    False
    >>> with lock:
    ...    lock.is_locked()
    True
    >>> 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...
    >>> 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

PACKAGE CONTENTS
    linklockfile
    mkdirlockfile
    pidlockfile
    sqlitelockfile
    symlinklockfile

SUBMODULES
    _llf

CLASSES
    builtins.Exception(builtins.BaseException)
        Error
            LockError
                AlreadyLocked
                LockFailed
                LockTimeout
            UnlockError
                NotLocked
                NotMyLock
    _SharedBase(builtins.object)
        LockBase

    class AlreadyLocked(LockError)
     |  Some other thread/process is locking the file.
     |
     |  >>> try:
     |  ...   raise AlreadyLocked
     |  ... except LockError:
     |  ...   pass
     |
     |  Method resolution order:
     |      AlreadyLocked
     |      LockError
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors inherited from Error:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class Error(builtins.Exception)
     |  Base class for other exceptions.
     |
     |  >>> try:
     |  ...   raise Error
     |  ... except Exception:
     |  ...   pass
     |
     |  Method resolution order:
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors defined here:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class LockBase(_SharedBase)
     |  LockBase(path, threaded=True, timeout=None)
     |
     |  Base class for platform-specific lock classes.
     |
     |  Method resolution order:
     |      LockBase
     |      _SharedBase
     |      builtins.object
     |
     |  Methods defined here:
     |
     |  __init__(self, path, threaded=True, timeout=None)
     |      >>> lock = LockBase('somefile')
     |      >>> lock = LockBase('somefile', threaded=False)
     |
     |  __repr__(self)
     |      Return repr(self).
     |
     |  break_lock(self)
     |      Remove a lock.  Useful if a locking thread failed to unlock.
     |
     |  i_am_locking(self)
     |      Return True if this object is locking the file.
     |
     |  is_locked(self)
     |      Tell whether or not the file is locked.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from _SharedBase:
     |
     |  __enter__(self)
     |      Context manager support.
     |
     |  __exit__(self, *_exc)
     |      Context manager support.
     |
     |  acquire(self, timeout=None)
     |      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.
     |
     |  release(self)
     |      Release the lock.
     |
     |      If the file is not locked, raise NotLocked.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from _SharedBase:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)

    class LockError(Error)
     |  Base class for error arising from attempts to acquire the lock.
     |
     |  >>> try:
     |  ...   raise LockError
     |  ... except Error:
     |  ...   pass
     |
     |  Method resolution order:
     |      LockError
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors inherited from Error:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class LockFailed(LockError)
     |  Lock file creation failed for some other reason.
     |
     |  >>> try:
     |  ...   raise LockFailed
     |  ... except LockError:
     |  ...   pass
     |
     |  Method resolution order:
     |      LockFailed
     |      LockError
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors inherited from Error:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class LockTimeout(LockError)
     |  Raised when lock creation fails within a user-defined period of time.
     |
     |  >>> try:
     |  ...   raise LockTimeout
     |  ... except LockError:
     |  ...   pass
     |
     |  Method resolution order:
     |      LockTimeout
     |      LockError
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors inherited from Error:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class NotLocked(UnlockError)
     |  Raised when an attempt is made to unlock an unlocked file.
     |
     |  >>> try:
     |  ...   raise NotLocked
     |  ... except UnlockError:
     |  ...   pass
     |
     |  Method resolution order:
     |      NotLocked
     |      UnlockError
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors inherited from Error:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class NotMyLock(UnlockError)
     |  Raised when an attempt is made to unlock a file someone else locked.
     |
     |  >>> try:
     |  ...   raise NotMyLock
     |  ... except UnlockError:
     |  ...   pass
     |
     |  Method resolution order:
     |      NotMyLock
     |      UnlockError
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors inherited from Error:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class UnlockError(Error)
     |  Base class for errors arising from attempts to release the lock.
     |
     |  >>> try:
     |  ...   raise UnlockError
     |  ... except Error:
     |  ...   pass
     |
     |  Method resolution order:
     |      UnlockError
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Data descriptors inherited from Error:
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

FUNCTIONS
    LinkFileLock(*args, **kwds)
        Factory function provided for backwards compatibility.

        Do not use in new code.  Instead, import LinkLockFile from the
        lockfile.linklockfile module.

    MkdirFileLock(*args, **kwds)
        Factory function provided for backwards compatibility.

        Do not use in new code.  Instead, import MkdirLockFile from the
        lockfile.mkdirlockfile module.

    SQLiteFileLock(*args, **kwds)
        Factory function provided for backwards compatibility.

        Do not use in new code.  Instead, import SQLiteLockFile from the
        lockfile.mkdirlockfile module.

    locked(path, timeout=None)
        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(...):
                 ...

DATA
    __all__ = ['Error', 'LockError', 'LockTimeout', 'AlreadyLocked', 'Lock...

FILE
    /usr/lib/python3/dist-packages/lockfile/__init__.py



Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:14 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 TransitionalValid CSS!

^_back to top