Debian Codegraph @

tests/isolated/patcher_existing_locks_locked.py

raw
1 __test__ = False
2
3
4 def take(lock, sync1, sync2):
5 sync2.acquire()
6 sync1.release()
7 with lock:
8 sync2.release()
9
10
11 if __name__ == '__main__':
12 import sys
13 import threading
14 lock = threading.RLock()
15 lock.acquire()
16 import eventlet
17 eventlet.monkey_patch()
18
19 lock.release()
20 try:
21 lock.release()
22 except RuntimeError as e:
23 assert e.args == ('cannot release un-acquired lock',)
24 lock.acquire()
25
26 sync1 = threading.Lock()
27 sync2 = threading.Lock()
28 sync1.acquire()
29 eventlet.spawn(take, lock, sync1, sync2)
30 # Ensure sync2 has been taken
31 with sync1:
32 pass
33
34 # an RLock should be reentrant
35 lock.acquire()
36 lock.release()
37 lock.release()
38 # To acquire sync2, 'take' must have acquired lock, which has been locked
39 # until now
40 sync2.acquire()
41
42 print('pass')