On this page
threading.RLock
Prev: threading.main_thread | Up: threading | Next: threading.Semaphore
Rel: threading.active_count, threading.Barrier, threading.BoundedSemaphore, threading.BrokenBarrierError
Ref: docs.python.org — threading.RLock
Tags: #public #python3 #stdlib #threading
Import
import threading
from threading import RLock
Signature & Overview
threading.RLock(*args, **kwargs)
Factory function that returns a new reentrant lock.
Usage
import threading
rlock = threading.RLock()
with rlock:
with rlock: # same thread can re-acquire without deadlocking
assert True
Gotchas
- Must be released as many times as acquired:
with rlock:handles this automatically. - Only the owning thread can release it: Unlike
Lock, another thread callingrlock.release()raisesRuntimeError.
REPL Inspect
from threading import RLock
help(RLock)
Linked from
Related notes
- tuts/python3/stdlib_module/threading/main_thread Linked here; links to this page; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/Semaphore Linked here; links to this page; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/threading/active_count Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/Barrier Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/BoundedSemaphore Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/BrokenBarrierError Linked here; shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/Condition shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/current_thread shared tags: #stdlib, #threading
- tuts/python3/stdlib_module/threading/enumerate shared tags: #stdlib, #threading