The Python multiprocessing
module has a class for reentrant/recursive locks:
from multiprocessing import RLock
l = RLock()
l.acquire()
l.acquire()
l.release()
l.release()
This works great for processes that were forked from a common parent process and, hence, can share the same RLock
object. However, for situations with independent processes (example: web server + cron job), one would need a named lock. Unfortunately, RLock()
does not accept a name argument for the lock. Is there a solution that allows to do something like this?
l = RLock('mylock')
l.acquire()
l.release()
Check out oslo_concurrency.lockutils
. It has a lock
context manager and a synchronized
decorator, both of which take a name and other handy interprocess-friendly parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With