{
    "mode": "pydoc",
    "parameter": "lockfile",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/lockfile/json",
    "generated": "2026-06-02T15:03:39Z",
    "sections": {
        "NAME": {
            "content": "lockfile - lockfile.py - Platform-independent advisory file locks.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Requires Python 2.5 unless you apply 2.4.diff\nLocking is done on a per-thread basis instead of a per-process basis.\n\nUsage:\n\n>>> lock = LockFile('somefile')\n>>> try:\n...     lock.acquire()\n... except AlreadyLocked:\n...     print('somefile', \"is locked already.\")\n... except LockFailed:\n...     print('somefile', \"can't be locked.\")\n... else:\n...     print(\"got lock\")\ngot lock\n>>> lock.islocked()\nTrue\n>>> lock.release()\n\n>>> lock = LockFile('somefile')\n>>> lock.islocked()\nFalse\n>>> with lock:\n...    lock.islocked()\nTrue\n>>> lock.islocked()\nFalse\n\n>>> lock = LockFile('somefile')\n>>> # It is okay to lock twice from the same thread...\n>>> with lock:\n...     lock.acquire()\n...\n>>> # Though no counter is kept, so you can't unlock multiple times...\n>>> lock.islocked()\nFalse\n\nExceptions:\n\nError - base class for other exceptions\nLockError - base class for all locking exceptions\nAlreadyLocked - Another thread or process already holds the lock\nLockFailed - Lock failed for some other reason\nUnlockError - base class for all unlocking exceptions\nAlreadyUnlocked - File was not locked.\nNotMyLock - File was locked but not by the current thread/process\n",
            "subsections": []
        },
        "PACKAGE CONTENTS": {
            "content": "linklockfile\nmkdirlockfile\npidlockfile\nsqlitelockfile\nsymlinklockfile\n",
            "subsections": []
        },
        "SUBMODULES": {
            "content": "llf\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.Exception(builtins.BaseException)\nError\nLockError\nAlreadyLocked\nLockFailed\nLockTimeout\nUnlockError\nNotLocked\nNotMyLock\nSharedBase(builtins.object)\nLockBase\n",
            "subsections": [
                {
                    "name": "class AlreadyLocked",
                    "content": "|  Some other thread/process is locking the file.\n|\n|  >>> try:\n|  ...   raise AlreadyLocked\n|  ... except LockError:\n|  ...   pass\n|\n|  Method resolution order:\n|      AlreadyLocked\n|      LockError\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors inherited from Error:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class Error",
                    "content": "|  Base class for other exceptions.\n|\n|  >>> try:\n|  ...   raise Error\n|  ... except Exception:\n|  ...   pass\n|\n|  Method resolution order:\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors defined here:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class LockBase",
                    "content": "|  LockBase(path, threaded=True, timeout=None)\n|\n|  Base class for platform-specific lock classes.\n|\n|  Method resolution order:\n|      LockBase\n|      SharedBase\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  init(self, path, threaded=True, timeout=None)\n|      >>> lock = LockBase('somefile')\n|      >>> lock = LockBase('somefile', threaded=False)\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  breaklock(self)\n|      Remove a lock.  Useful if a locking thread failed to unlock.\n|\n|  iamlocking(self)\n|      Return True if this object is locking the file.\n|\n|  islocked(self)\n|      Tell whether or not the file is locked.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from SharedBase:\n|\n|  enter(self)\n|      Context manager support.\n|\n|  exit(self, *exc)\n|      Context manager support.\n|\n|  acquire(self, timeout=None)\n|      Acquire the lock.\n|\n|      * If timeout is omitted (or None), wait forever trying to lock the\n|        file.\n|\n|      * If timeout > 0, try to acquire the lock for that many seconds.  If\n|        the lock period expires and the file is still locked, raise\n|        LockTimeout.\n|\n|      * If timeout <= 0, raise AlreadyLocked immediately if the file is\n|        already locked.\n|\n|  release(self)\n|      Release the lock.\n|\n|      If the file is not locked, raise NotLocked.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from SharedBase:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n"
                },
                {
                    "name": "class LockError",
                    "content": "|  Base class for error arising from attempts to acquire the lock.\n|\n|  >>> try:\n|  ...   raise LockError\n|  ... except Error:\n|  ...   pass\n|\n|  Method resolution order:\n|      LockError\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors inherited from Error:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class LockFailed",
                    "content": "|  Lock file creation failed for some other reason.\n|\n|  >>> try:\n|  ...   raise LockFailed\n|  ... except LockError:\n|  ...   pass\n|\n|  Method resolution order:\n|      LockFailed\n|      LockError\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors inherited from Error:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class LockTimeout",
                    "content": "|  Raised when lock creation fails within a user-defined period of time.\n|\n|  >>> try:\n|  ...   raise LockTimeout\n|  ... except LockError:\n|  ...   pass\n|\n|  Method resolution order:\n|      LockTimeout\n|      LockError\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors inherited from Error:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class NotLocked",
                    "content": "|  Raised when an attempt is made to unlock an unlocked file.\n|\n|  >>> try:\n|  ...   raise NotLocked\n|  ... except UnlockError:\n|  ...   pass\n|\n|  Method resolution order:\n|      NotLocked\n|      UnlockError\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors inherited from Error:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class NotMyLock",
                    "content": "|  Raised when an attempt is made to unlock a file someone else locked.\n|\n|  >>> try:\n|  ...   raise NotMyLock\n|  ... except UnlockError:\n|  ...   pass\n|\n|  Method resolution order:\n|      NotMyLock\n|      UnlockError\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors inherited from Error:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class UnlockError",
                    "content": "|  Base class for errors arising from attempts to release the lock.\n|\n|  >>> try:\n|  ...   raise UnlockError\n|  ... except Error:\n|  ...   pass\n|\n|  Method resolution order:\n|      UnlockError\n|      Error\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors inherited from Error:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.Exception:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "LinkFileLock(*args, kwds)\nFactory function provided for backwards compatibility.\n\nDo not use in new code.  Instead, import LinkLockFile from the\nlockfile.linklockfile module.\n\nMkdirFileLock(*args, kwds)\nFactory function provided for backwards compatibility.\n\nDo not use in new code.  Instead, import MkdirLockFile from the\nlockfile.mkdirlockfile module.\n\nSQLiteFileLock(*args, kwds)\nFactory function provided for backwards compatibility.\n\nDo not use in new code.  Instead, import SQLiteLockFile from the\nlockfile.mkdirlockfile module.\n",
            "subsections": [
                {
                    "name": "locked",
                    "content": "Decorator which enables locks for decorated function.\n\nArguments:\n- path: path for lockfile.\n- timeout (optional): Timeout for acquiring lock.\n\nUsage:\n@locked('/var/run/myname', timeout=0)\ndef myname(...):\n...\n"
                }
            ]
        },
        "DATA": {
            "content": "all = ['Error', 'LockError', 'LockTimeout', 'AlreadyLocked', 'Lock...\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3/dist-packages/lockfile/init.py\n\n",
            "subsections": []
        }
    },
    "summary": "lockfile - lockfile.py - Platform-independent advisory file locks.",
    "flags": [],
    "examples": [],
    "see_also": []
}