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:
sobolevn 2025-04-08 11:14:12 +03:00 committed by GitHub
parent 6cd1d6c6b1
commit f7305a06c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 89 additions and 6 deletions

View file

@ -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().