-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as not planned
Closed as not planned
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Description
Documentation
Because RLock has an "owner", it is fully released when its acquiring thread exits, no matter how many times it is acquired. The ownerless Lock on the other hand, stays locked when its acquiring thread exits. This should be documented because it can lead to hard to debug errors.
Example code to see this difference:
def f(lock):
print('f lock:', lock.acquire(False))
print('f relock:', lock.acquire(False))
def g(lock):
print('g lock:', lock.acquire(False))
print('g relock:', lock.acquire(False))
print('Lock:')
lock = threading.Lock()
t1 = threading.Thread(target=f, args=(lock,))
t2 = threading.Thread(target=g, args=(lock,))
t1.start()
t1.join()
t2.start()
t2.join()
print()
print('RLock:')
lock = threading.RLock()
t1 = threading.Thread(target=f, args=(lock,))
t2 = threading.Thread(target=g, args=(lock,))
t1.start()
t1.join()
t2.start()
t2.join()
Output:
Lock:
f lock: True
f relock: False
g lock: False
g relock: False
RLock:
f lock: True
f relock: True
g lock: True
g relock: True
Linked PRs
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Projects
Status
Todo