{
    "content": [
        {
            "type": "text",
            "text": "# lockfile (pydoc)\n\n**Summary:** lockfile - lockfile.py - Platform-independent advisory file locks.\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **DESCRIPTION** (47 lines)\n- **PACKAGE CONTENTS** (6 lines)\n- **SUBMODULES** (2 lines)\n- **CLASSES** (12 lines) — 9 subsections\n  - class AlreadyLocked (76 lines)\n  - class Error (74 lines)\n  - class LockBase (63 lines)\n  - class LockError (75 lines)\n  - class LockFailed (76 lines)\n  - class LockTimeout (76 lines)\n  - class NotLocked (76 lines)\n  - class NotMyLock (76 lines)\n  - class UnlockError (75 lines)\n- **FUNCTIONS** (18 lines) — 1 subsections\n  - locked (11 lines)\n- **DATA** (2 lines)\n- **FILE** (3 lines)\n\n## Full Content\n\n### NAME\n\nlockfile - lockfile.py - Platform-independent advisory file locks.\n\n### DESCRIPTION\n\nRequires 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\n### PACKAGE CONTENTS\n\nlinklockfile\nmkdirlockfile\npidlockfile\nsqlitelockfile\nsymlinklockfile\n\n### SUBMODULES\n\nllf\n\n### CLASSES\n\nbuiltins.Exception(builtins.BaseException)\nError\nLockError\nAlreadyLocked\nLockFailed\nLockTimeout\nUnlockError\nNotLocked\nNotMyLock\nSharedBase(builtins.object)\nLockBase\n\n#### class AlreadyLocked\n\n|  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\n#### class Error\n\n|  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\n#### class LockBase\n\n|  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\n#### class LockError\n\n|  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\n#### class LockFailed\n\n|  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\n#### class LockTimeout\n\n|  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\n#### class NotLocked\n\n|  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\n#### class NotMyLock\n\n|  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\n#### class UnlockError\n\n|  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\n### FUNCTIONS\n\nLinkFileLock(*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\n#### locked\n\nDecorator 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\n### DATA\n\nall = ['Error', 'LockError', 'LockTimeout', 'AlreadyLocked', 'Lock...\n\n### FILE\n\n/usr/lib/python3/dist-packages/lockfile/init.py\n\n"
        }
    ],
    "structuredContent": {
        "command": "lockfile",
        "section": "",
        "mode": "pydoc",
        "summary": "lockfile - lockfile.py - Platform-independent advisory file locks.",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 47,
                "subsections": []
            },
            {
                "name": "PACKAGE CONTENTS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SUBMODULES",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "CLASSES",
                "lines": 12,
                "subsections": [
                    {
                        "name": "class AlreadyLocked",
                        "lines": 76
                    },
                    {
                        "name": "class Error",
                        "lines": 74
                    },
                    {
                        "name": "class LockBase",
                        "lines": 63
                    },
                    {
                        "name": "class LockError",
                        "lines": 75
                    },
                    {
                        "name": "class LockFailed",
                        "lines": 76
                    },
                    {
                        "name": "class LockTimeout",
                        "lines": 76
                    },
                    {
                        "name": "class NotLocked",
                        "lines": 76
                    },
                    {
                        "name": "class NotMyLock",
                        "lines": 76
                    },
                    {
                        "name": "class UnlockError",
                        "lines": 75
                    }
                ]
            },
            {
                "name": "FUNCTIONS",
                "lines": 18,
                "subsections": [
                    {
                        "name": "locked",
                        "lines": 11
                    }
                ]
            },
            {
                "name": "DATA",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "FILE",
                "lines": 3,
                "subsections": []
            }
        ]
    }
}