Suppose I need to do the following:
global_lock.acquire()
local_lock = threading.Lock()
local_lock.acquire()
register_local_lock(local_lock, some_associated_data)
global_lock.release()
do_some_work()
local_lock.release()
Q: How can I achieve the same thing using with
statement?
P.S. In my application, there actually exist a workaround that separates the two lock acquisition. However, I think there could be senarios where the two lock acquisition must stay interleaved, so I'm still posting, with an additional question:
Q: Can all interleaved lock acquisition be eliminated by refactoring?