# Buildsheet autogenerated by ravenadm tool -- Do not edit. NAMEBASE= python-django-pglocks VERSION= 1.0.4 KEYWORDS= python VARIANTS= v12 v13 SDESC[v12]= Advisory lock context for PostgreSQL (3.12) SDESC[v13]= Advisory lock context for PostgreSQL (3.13) HOMEPAGE= https://github.com/Xof/django-pglocks CONTACT= Python_Automaton[python@ironwolf.systems] DOWNLOAD_GROUPS= main SITES[main]= PYPI/d/django-pglocks DISTFILE[1]= django-pglocks-1.0.4.tar.gz:main DIST_SUBDIR= python-src DF_INDEX= 1 SPKGS[v12]= single SPKGS[v13]= single OPTIONS_AVAILABLE= PY312 PY313 OPTIONS_STANDARD= none VOPTS[v12]= PY312=ON PY313=OFF VOPTS[v13]= PY312=OFF PY313=ON DISTNAME= django-pglocks-1.0.4 GENERATED= yes [PY312].BUILDRUN_DEPENDS_ON= python-six:single:v12 [PY312].USES_ON= python:v12,sutools [PY313].BUILDRUN_DEPENDS_ON= python-six:single:v13 [PY313].USES_ON= python:v13,sutools [FILE:3400:descriptions/desc.single] ============== django-pglocks ============== django-pglocks provides a useful context manager to manage PostgreSQL advisory locks. It requires Django (tested with 1.5), PostgreSQL, and (probably) psycopg2. Advisory Locks ============== Advisory 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. It's entirely up to the application to correctly acquire the right lock. Advisory 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. Currently, 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. Installing ========== Just use pip:: pip install django-pglocks Transactions ============ This assumes you are controlling transactions within the view; do not use this if you controlling transactions through the Django transation middleware. Usage ===== Usage example:: from django_pglocks import advisory_lock lock_id = 'some lock' with advisory_lock(lock_id) as acquired: # code that should be inside of the lock. The 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. The parameters are: * 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). * 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. * 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. * using (default None) -- The database alias on which to attempt to acquire the lock. If None, the default connection is used. Contributing ============ To run the test suite, you must create a user and a database:: $ createuser -s -P django_pglocks Enter password for new role: django_pglocks Enter it again: django_pglocks $ createdb django_pglocks -O django_pglocks You can then run the tests with:: $ DJANGO_SETTINGS_MODULE=django_pglocks.test_settings PYTHONPATH=. django-admin.py test License ======= [FILE:117:distinfo] 3c47c66fbfbd268ef46269673a0516a039539b0972b8ed2ec9cfee44c4b65523 4085 python-src/django-pglocks-1.0.4.tar.gz