locket.py: File-based locks for Python on Linux and Windows
===========================================================
Locket implements a file-based lock that can be used by multiple processes provided they use the same path.
.. code-block:: python
import locket
# Wait for lock
with locket.lock_file("path/to/lock/file"):
perform_action()
# Raise LockError if lock cannot be acquired immediately
with locket.lock_file("path/to/lock/file", timeout=0):
perform_action()
# Raise LockError if lock cannot be acquired after thirty seconds
with locket.lock_file("path/to/lock/file", timeout=30):
perform_action()
# Without context managers:
lock = locket.lock_file("path/to/lock/file")
try:
lock.acquire()
perform_action()
finally:
lock.release()
Locks largely behave as (non-reentrant) ``Lock`` instances from the ``threading``
module in the standard library. Specifically, their behaviour is:
* Locks are uniquely identified by the file being locked,
both in the same process and across different processes.
* Locks are either in a locked or unlocked state.
* When the lock is unlocked, calling ``acquire()`` returns immediately and changes
the lock state to locked.
* When the lock is locked, calling ``acquire()`` will block until the lock state
changes to unlocked, or until the timeout expires.
* If a process holds a lock, any thread in that process can call ``release()`` to
change the state to unlocked.
* Calling ``release()`` on an unlocked lock raises ``LockError``.
* Behaviour of locks after ``fork`` is undefined.
Installation
------------
.. code-block:: sh
pip install locket
Raw data
{
"_id": null,
"home_page": "http://github.com/mwilliamson/locket.py",
"name": "locket",
"maintainer": "",
"docs_url": null,
"requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
"maintainer_email": "",
"keywords": "lock filelock lockfile process",
"author": "Michael Williamson",
"author_email": "mike@zwobble.org",
"download_url": "https://files.pythonhosted.org/packages/2f/83/97b29fe05cb6ae28d2dbd30b81e2e402a3eed5f460c26e9eaa5895ceacf5/locket-1.0.0.tar.gz",
"platform": null,
"description": "locket.py: File-based locks for Python on Linux and Windows\n===========================================================\n\nLocket implements a file-based lock that can be used by multiple processes provided they use the same path.\n\n.. code-block:: python\n\n import locket\n\n # Wait for lock\n with locket.lock_file(\"path/to/lock/file\"):\n perform_action()\n\n # Raise LockError if lock cannot be acquired immediately\n with locket.lock_file(\"path/to/lock/file\", timeout=0):\n perform_action()\n\n # Raise LockError if lock cannot be acquired after thirty seconds\n with locket.lock_file(\"path/to/lock/file\", timeout=30):\n perform_action()\n\n # Without context managers:\n lock = locket.lock_file(\"path/to/lock/file\")\n try:\n lock.acquire()\n perform_action()\n finally:\n lock.release()\n\nLocks largely behave as (non-reentrant) ``Lock`` instances from the ``threading``\nmodule in the standard library. Specifically, their behaviour is:\n\n* Locks are uniquely identified by the file being locked,\n both in the same process and across different processes.\n\n* Locks are either in a locked or unlocked state.\n\n* When the lock is unlocked, calling ``acquire()`` returns immediately and changes\n the lock state to locked.\n\n* When the lock is locked, calling ``acquire()`` will block until the lock state\n changes to unlocked, or until the timeout expires.\n\n* If a process holds a lock, any thread in that process can call ``release()`` to\n change the state to unlocked.\n\n* Calling ``release()`` on an unlocked lock raises ``LockError``.\n\n* Behaviour of locks after ``fork`` is undefined.\n\nInstallation\n------------\n\n.. code-block:: sh\n\n pip install locket\n\n\n",
"bugtrack_url": null,
"license": "BSD-2-Clause",
"summary": "File-based locks for Python on Linux and Windows",
"version": "1.0.0",
"split_keywords": [
"lock",
"filelock",
"lockfile",
"process"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "9454e2c0701d6de9ce1bfa40ab78e9b8",
"sha256": "b6c819a722f7b6bd955b80781788e4a66a55628b858d347536b7e81325a3a5e3"
},
"downloads": -1,
"filename": "locket-1.0.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "9454e2c0701d6de9ce1bfa40ab78e9b8",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
"size": 4398,
"upload_time": "2022-04-20T22:04:42",
"upload_time_iso_8601": "2022-04-20T22:04:42.230844Z",
"url": "https://files.pythonhosted.org/packages/db/bc/83e112abc66cd466c6b83f99118035867cecd41802f8d044638aa78a106e/locket-1.0.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "fff6d2fcd92fbeb9af9dbc260eb0b5e8",
"sha256": "5c0d4c052a8bbbf750e056a8e65ccd309086f4f0f18a2eac306a8dfa4112a632"
},
"downloads": -1,
"filename": "locket-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "fff6d2fcd92fbeb9af9dbc260eb0b5e8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
"size": 4350,
"upload_time": "2022-04-20T22:04:44",
"upload_time_iso_8601": "2022-04-20T22:04:44.312465Z",
"url": "https://files.pythonhosted.org/packages/2f/83/97b29fe05cb6ae28d2dbd30b81e2e402a3eed5f460c26e9eaa5895ceacf5/locket-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-04-20 22:04:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "mwilliamson",
"github_project": "locket.py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "locket"
}