pals icon indicating copy to clipboard operation
pals copied to clipboard

Support nested locks for the same lock on the same connection

Open rsyring opened this issue 6 years ago • 1 comments

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.

rsyring avatar Nov 14 '19 00:11 rsyring

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

jobh avatar Aug 28 '20 08:08 jobh