mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-115942: Add locked
to several multiprocessing locks (#115944)
Co-authored-by: mpage <mpage@cs.stanford.edu> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
6cd1d6c6b1
commit
f7305a06c7
10 changed files with 89 additions and 6 deletions
|
@ -241,6 +241,10 @@ class _RLock:
|
|||
def __exit__(self, t, v, tb):
|
||||
self.release()
|
||||
|
||||
def locked(self):
|
||||
"""Return whether this object is locked."""
|
||||
return self._count > 0
|
||||
|
||||
# Internal methods used by condition variables
|
||||
|
||||
def _acquire_restore(self, state):
|
||||
|
@ -286,9 +290,10 @@ class Condition:
|
|||
if lock is None:
|
||||
lock = RLock()
|
||||
self._lock = lock
|
||||
# Export the lock's acquire() and release() methods
|
||||
# Export the lock's acquire(), release(), and locked() methods
|
||||
self.acquire = lock.acquire
|
||||
self.release = lock.release
|
||||
self.locked = lock.locked
|
||||
# If the lock defines _release_save() and/or _acquire_restore(),
|
||||
# these override the default implementations (which just call
|
||||
# release() and acquire() on the lock). Ditto for _is_owned().
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue