Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
Closed
Description
Feature or enhancement
Proposal:
Current implementation relies on both_acquireLock()
and_releaseLock()
being called, otherwise a lock may never be released:
def_acquireLock():""" Acquire the module-level lock for serializing access to shared data. This should be released with _releaseLock(). """if_lock:try:_lock.acquire()exceptBaseException:_lock.release()raisedef_releaseLock():""" Release the module-level lock acquired by calling _acquireLock(). """if_lock:_lock.release()
The majority of usages of_acquireLock()
manually add a try/except/finally block to ensure that the lock is released if an exception is thrown. Some usages of_acquireLock()
have no safety.
The proposal is to alter the usage of_acquireLock()
to be a context manager that deals with acquiring and releasing automatically rather than requiring try/except/finally blocks to be used anywhere the function is called.
For example,
usage before:
_acquireLock()try: ...finally:_releaseLock()
proposed usage:
with_acquireLock(): ...
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response