diff options
author | sobolevn <mail@sobolevn.me> | 2025-04-08 08:14:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-08 08:14:12 (GMT) |
commit | f7305a06c7a322d23b39ad9d16af814d467624c6 (patch) | |
tree | 8a25dede6c059e01ae98c63d737ac0d0c1987b58 /Lib/threading.py | |
parent | 6cd1d6c6b142697fb72f422b7b448c27ebc30534 (diff) | |
download | cpython-f7305a06c7a322d23b39ad9d16af814d467624c6.zip cpython-f7305a06c7a322d23b39ad9d16af814d467624c6.tar.gz cpython-f7305a06c7a322d23b39ad9d16af814d467624c6.tar.bz2 |
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>
Diffstat (limited to 'Lib/threading.py')
-rw-r--r-- | Lib/threading.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index da9cdf0..0dc1d32 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -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(). |