{ "info": { "author": "Christophe Pettus", "author_email": "xof@thebuild.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development" ], "description": "==============\ndjango-pglocks\n==============\n\ndjango-pglocks provides a useful context manager to manage PostgreSQL advisory locks. It requires Django (tested with 1.5), PostgreSQL, and (probably) psycopg2.\n\nAdvisory Locks\n==============\n\nAdvisory locks are application-level locks that are acquired and released purely by the client of the database; PostgreSQL never acquires them on its own. They are very useful as a way of signalling to other sessions that a higher-level resource than a single row is in use, without having to lock an entire table or some other structure.\n\nIt's entirely up to the application to correctly acquire the right lock.\n\nAdvisory locks are either session locks or transaction locks. A session lock is held until the database session disconnects (or is reset); a transaction lock is held until the transaction terminates.\n\nCurrently, the context manager only creates session locks, as the behavior of a lock persisting after the context body has been exited is surprising, and there's no way of releasing a transaction-scope advisory lock except to exit the transaction.\n\nInstalling\n==========\n\nJust use pip::\n\n pip install django-pglocks\n \nTransactions\n============\n\nThis assumes you are controlling transactions within the view; do not use this\nif you controlling transactions through the Django transation middleware.\n\nUsage\n=====\n\nUsage example::\n\n from django_pglocks import advisory_lock\n\n lock_id = 'some lock'\n\n with advisory_lock(lock_id) as acquired:\n # code that should be inside of the lock.\n\nThe context manager attempts to take the lock, and then executes the code inside the context with the lock acquired. The lock is released when the context exits, either normally or via exception.\n\nThe parameters are:\n\n* ``lock_id`` -- The ID of the lock to acquire. It can be a string, long, or a tuple of two ints. If it's a string, the hash of the string is used as the lock ID (PostgreSQL advisory lock IDs are 64 bit values).\n\n* ``shared`` (default False) -- If True, a shared lock is taken. Any number of sessions can hold a shared lock; if another session attempts to take an exclusive lock, it will wait until all shared locks are released; if a session is holding a shared lock, it will block attempts to take a shared lock. If False (the default), an exclusive lock is taken.\n\n* ``wait`` (default True) -- If True (the default), the context manager will wait until the lock has been acquired before executing the content; in that case, it always returns True (unless a deadlock occurs, in which case an exception is thrown). If False, the context manager will return immediately even if it cannot take the lock, in which case it returns false. Note that the context body is *always* executed; the only way to tell in the ``wait=False`` case whether or not the lock was acquired is to check the returned value.\n\n* ``using`` (default None) -- The database alias on which to attempt to acquire the lock. If None, the default connection is used.\n\nContributing\n============\n\nTo run the test suite, you must create a user and a database::\n\n $ createuser -s -P django_pglocks\n Enter password for new role: django_pglocks\n Enter it again: django_pglocks\n $ createdb django_pglocks -O django_pglocks\n\nYou can then run the tests with::\n\n $ DJANGO_SETTINGS_MODULE=django_pglocks.test_settings PYTHONPATH=. django-admin.py test\n\nLicense\n=======\n\nIt's released under the `MIT License `_.\n\nChange History 1.0.2\n====================\n\nFixed bug where lock would not be released when acquired with wait=False.\nMany thanks to Aymeric Augustin for finding this!\n\nChange History 1.0.1\n====================\n\nRemoved transaction-level locks, as their behavior was somewhat surprising (having the lock persist after the context manager exited was unexpected behavior).\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Xof/django-pglocks", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-pglocks", "package_url": "https://pypi.org/project/django-pglocks/", "platform": "", "project_url": "https://pypi.org/project/django-pglocks/", "project_urls": { "Homepage": "https://github.com/Xof/django-pglocks" }, "release_url": "https://pypi.org/project/django-pglocks/1.0.3/", "requires_dist": null, "requires_python": "", "summary": "django_pglocks provides useful context managers for advisory locks for PostgreSQL.", "version": "1.0.3" }, "last_serial": 5646730, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "9606b2b9f18ae67fb8feec30aa137db7", "sha256": "22b6616e796756d74ea5f6cb1f7bc6aa118edb16d733dedbddf1dbc29bf1547f" }, "downloads": -1, "filename": "django-pglocks-1.0.tar.gz", "has_sig": false, "md5_digest": "9606b2b9f18ae67fb8feec30aa137db7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2890, "upload_time": "2013-07-02T13:04:21", "url": "https://files.pythonhosted.org/packages/40/6f/61eb03b0500126fae66bc963ae15c963c5e0c823a548c30b2fb1781936a1/django-pglocks-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "b9c0ae85dae593f9b03ed8e9d1f88450", "sha256": "e1405d68486c0b8daf1feae3172b54c902af59ffc14ec8c0e8ef2f8c4e22356f" }, "downloads": -1, "filename": "django-pglocks-1.0.1.tar.gz", "has_sig": false, "md5_digest": "b9c0ae85dae593f9b03ed8e9d1f88450", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2973, "upload_time": "2013-07-02T14:16:52", "url": "https://files.pythonhosted.org/packages/e6/c3/796900bdde01be03fdf2b4380716df9b6b72bcb8bd252c7e3b739a177677/django-pglocks-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "272e39c5341123b9d63a323bab9b2abd", "sha256": "9405ee54bbf157bb16b814f20ea7ad9d82d5cf26f9bf3ea8e3a71032179844cf" }, "downloads": -1, "filename": "django-pglocks-1.0.2.tar.gz", "has_sig": false, "md5_digest": "272e39c5341123b9d63a323bab9b2abd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4015, "upload_time": "2016-07-07T04:12:10", "url": "https://files.pythonhosted.org/packages/a0/43/ee0a6215a992026ba3961136919a8ca56a9f0529430d486682606c07e91d/django-pglocks-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "6728442955b532b206ce66a938f4ec9e", "sha256": "daa3323de355b9057d8f37143e2ae8d283925fd25128ab66bb8c700d000111d9" }, "downloads": -1, "filename": "django-pglocks-1.0.3.tar.gz", "has_sig": false, "md5_digest": "6728442955b532b206ce66a938f4ec9e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4033, "upload_time": "2019-08-07T19:52:43", "url": "https://files.pythonhosted.org/packages/5f/1d/07ec0374b4f163dde5c79a4e2f1aa61b664ab121860d23ffa22a83a593c0/django-pglocks-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6728442955b532b206ce66a938f4ec9e", "sha256": "daa3323de355b9057d8f37143e2ae8d283925fd25128ab66bb8c700d000111d9" }, "downloads": -1, "filename": "django-pglocks-1.0.3.tar.gz", "has_sig": false, "md5_digest": "6728442955b532b206ce66a938f4ec9e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4033, "upload_time": "2019-08-07T19:52:43", "url": "https://files.pythonhosted.org/packages/5f/1d/07ec0374b4f163dde5c79a4e2f1aa61b664ab121860d23ffa22a83a593c0/django-pglocks-1.0.3.tar.gz" } ] }