Usage
-----
::
from pylock import Lock
with Lock('a_key', expires=60, timeout=10):
# do something that should only be done one at a time
Configuration
-------------
Backends
~~~~~~~~
There are three available backends:
Open (non-locking) backend
^^^^^^^^^^^^^^^^^^^^^^^^^^
::
DEFAULT_BACKEND = {
'class': 'pylock.backends.open_lock.OpenLock',
'connection': 'open://'
}
**Warning** This backend is not a real lock since it can always be
acquired even if another instance has acquired it already. It is meant
to be used for testing when you don't want to depend on a running redis
or memcache instance and don't care about the lock working.
Redis backend
^^^^^^^^^^^^^
::
DEFAULT_BACKEND = {
'class': 'pylock.backends.redis_lock.RedisLock',
'connection': 'redis://'
}
Note: all fields after the scheme are optional, and will default to
localhost on port 6379, using database 0.
Memcache backend (coming soon)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``DEFAULT_TIMEOUT`` (default: 60)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If another client has already obtained the lock, sleep for a maximum of
this many seconds before giving up. A value of 0 means no wait (give up
right away).
The default timeout can be overridden when instantiating the lock.
``DEFAULT_EXPIRES`` (default: 10)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We consider any existing lock older than this many seconds to be invalid
in order to detect crashed clients. This value must be higher than it
takes the critical section to execute.
The default expires can be overridden when instantiating the lock.
``KEY_PREFIX`` (default ``'pylock:'``)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is used to prefix the key for the generated lock.
For ``Lock('somekey')``, the generated key will be ``'pylock:somekey'``
Inspired by
-----------
Redis backend
~~~~~~~~~~~~~
The redis backend is almost an exact copy of Ben Bangert's
```retools.lock`` <https://github.com/bbangert/retools/blob/master/retools/lock.py>`_
which is based on `Chris Lamb's
example <https://chris-lamb.co.uk/posts/distributing-locking-python-and-redis>`_
Memcache backend (coming soon)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The memcache backend is inspired by the following: -
https://github.com/snbuback/DistributedLock -
http://jbq.caraldi.com/2010/08/simple-distributed-lock-with-memcached.html
-
http://www.regexprn.com/2010/05/using-memcached-as-distributed-locking.html
Notes related to the 0.4 release
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Added a poetry lock file, but did not setup circleci builds
To build and publish a release:
poetry publish -r gemfury -u $GEMFURY_PUSH_TOKEN -p NOPASS --build
For testing I would suggest that you build and publish patch releases till it works in your app THEN publish a minor or major version
because if you republish multiple builds at the same version it is very difficult to get your app to install the new ones.
Poetry builds do not include test code the way that setup.py builds did.
Raw data
{
"_id": null,
"home_page": "http://github.com/waveaccounting/pylock",
"name": "pylock",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "lock redis",
"author": "Nathan Duthoit",
"author_email": "nathan@waveapps.com",
"download_url": "https://files.pythonhosted.org/packages/4f/ef/0c2fd3caaa308c0bf3db8f572e7fb40554bcc84a8c9258492bf9aa485dc0/pylock-0.4.tar.gz",
"platform": null,
"description": "Usage\n-----\n\n::\n\n from pylock import Lock\n\n with Lock('a_key', expires=60, timeout=10):\n # do something that should only be done one at a time\n\nConfiguration\n-------------\n\nBackends\n~~~~~~~~\n\nThere are three available backends:\n\nOpen (non-locking) backend\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n::\n\n DEFAULT_BACKEND = {\n 'class': 'pylock.backends.open_lock.OpenLock',\n 'connection': 'open://'\n }\n\n**Warning** This backend is not a real lock since it can always be\nacquired even if another instance has acquired it already. It is meant\nto be used for testing when you don't want to depend on a running redis\nor memcache instance and don't care about the lock working.\n\nRedis backend\n^^^^^^^^^^^^^\n\n::\n\n DEFAULT_BACKEND = {\n 'class': 'pylock.backends.redis_lock.RedisLock',\n 'connection': 'redis://'\n }\n\nNote: all fields after the scheme are optional, and will default to\nlocalhost on port 6379, using database 0.\n\nMemcache backend (coming soon)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n``DEFAULT_TIMEOUT`` (default: 60)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf another client has already obtained the lock, sleep for a maximum of\nthis many seconds before giving up. A value of 0 means no wait (give up\nright away).\n\nThe default timeout can be overridden when instantiating the lock.\n\n``DEFAULT_EXPIRES`` (default: 10)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nWe consider any existing lock older than this many seconds to be invalid\nin order to detect crashed clients. This value must be higher than it\ntakes the critical section to execute.\n\nThe default expires can be overridden when instantiating the lock.\n\n``KEY_PREFIX`` (default ``'pylock:'``)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis is used to prefix the key for the generated lock.\n\nFor ``Lock('somekey')``, the generated key will be ``'pylock:somekey'``\n\nInspired by\n-----------\n\nRedis backend\n~~~~~~~~~~~~~\n\nThe redis backend is almost an exact copy of Ben Bangert's\n```retools.lock`` <https://github.com/bbangert/retools/blob/master/retools/lock.py>`_\nwhich is based on `Chris Lamb's\nexample <https://chris-lamb.co.uk/posts/distributing-locking-python-and-redis>`_\n\nMemcache backend (coming soon)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe memcache backend is inspired by the following: -\nhttps://github.com/snbuback/DistributedLock -\nhttp://jbq.caraldi.com/2010/08/simple-distributed-lock-with-memcached.html\n-\nhttp://www.regexprn.com/2010/05/using-memcached-as-distributed-locking.html\n\n\n\nNotes related to the 0.4 release\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nAdded a poetry lock file, but did not setup circleci builds\nTo build and publish a release:\npoetry publish -r gemfury -u $GEMFURY_PUSH_TOKEN -p NOPASS --build \n\nFor testing I would suggest that you build and publish patch releases till it works in your app THEN publish a minor or major version\nbecause if you republish multiple builds at the same version it is very difficult to get your app to install the new ones.\n\nPoetry builds do not include test code the way that setup.py builds did.",
"bugtrack_url": null,
"license": "BSD",
"summary": "Python Distributed Lock",
"version": "0.4",
"project_urls": {
"Homepage": "http://github.com/waveaccounting/pylock"
},
"split_keywords": [
"lock",
"redis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4fef0c2fd3caaa308c0bf3db8f572e7fb40554bcc84a8c9258492bf9aa485dc0",
"md5": "a59b9b110e8d5efae11286f0a780d035",
"sha256": "3bea0dbe0d0ca6753d106a334aab857ed1628a0d18b70687f8633c704d1679d1"
},
"downloads": -1,
"filename": "pylock-0.4.tar.gz",
"has_sig": false,
"md5_digest": "a59b9b110e8d5efae11286f0a780d035",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9550,
"upload_time": "2023-06-19T17:12:56",
"upload_time_iso_8601": "2023-06-19T17:12:56.952712Z",
"url": "https://files.pythonhosted.org/packages/4f/ef/0c2fd3caaa308c0bf3db8f572e7fb40554bcc84a8c9258492bf9aa485dc0/pylock-0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-19 17:12:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "waveaccounting",
"github_project": "pylock",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "pylock"
}