pals
pals copied to clipboard
Support nested locks for the same lock on the same connection
PG advisory locks support nested locks. So, the same connection can request the same lock multiple times. We don't currently support that, but should consider it.
Even if not supported, the current behaviour is inconsistent - the lock can be acquired multiple times, but only released once:
>>> locker = pals.Locker('test', url)
>>> lock1, lock2 = locker.lock('t1'), locker.lock('t1')
>>> lock1.acquire(blocking=False)
True
>>> lock1.acquire(blocking=False)
True
>>> lock1.release()
True
>>> lock1.release()
False
>>> lock2.acquire(blocking=False)
False
>>> del lock1
>>> lock2.acquire(blocking=False)
True