librt.threading¶
The librt.threading module is part of the librt package on PyPI, and it includes
threading primitives.
Classes¶
Lock¶
- class Lock¶
A fast mutual exclusion lock. This can be used as a faster replacement for
threading.Lockin compiled code.Like
threading.Lock, aLockis unowned: it may be released by a thread other than the one that acquired it, and it doesn’t support reentrant (recursive) locking. A newly created lock is unlocked.Lockcan be used as a context manager. The lock is acquired (blocking) on entry and released on exit, including when the body raises an exception:def example(lock: Lock) -> None: with lock: ... # Critical section; the lock is held here.
Lockcannot be subclassed.Lockcannot be used withthreading.Condition.- acquire(blocking: bool = True) bool¶
Acquire the lock.
When blocking is true (the default), block (if needed) until the lock is available, acquire it, and return
True. When blocking is false, acquire the lock only if it can be done without blocking: returnTrueif the lock could be acquired, orFalseotherwise (it was already locked by some thread).Unlike
threading.Lock.acquire(), there is no timeout argument.
- release() None¶
Release the lock, allowing another thread (if any) that is blocked on
acquire()to proceed. Since the lock is unowned, it may be released from a thread other than the one that acquired it.Raise
RuntimeErrorif the lock is not currently held.