
In projects which dynamically determine whether to activate eventlet, it can be hard not to import a low level module like logging before eventlet. When logging is imported it initialises a threading.RLock which it uses to protect the logging configuration. If two greenthreads attempt to claim this lock, the second one will block the /native/ thread not just itself. As green systems usually only have one native thread, this will freeze the whole system. Search the GC for unsafe RLocks and replace their internal Lock with a safe one while monkey-patching. The tests pass, but were they to fail, the test process would never return. To deal with this, I've added a test dependency on subprocess32 which is a backport of the stdlib subprocess module from Python3. This offers a timeout option on Popen#communicate, which I've arbitrarily set at 30 seconds.
29 lines
489 B
Python
29 lines
489 B
Python
__test__ = False
|
|
|
|
|
|
def aaa(lock, e1, e2):
|
|
e1.set()
|
|
with lock:
|
|
e2.wait()
|
|
|
|
|
|
def bbb(lock, e1, e2):
|
|
e1.wait()
|
|
e2.set()
|
|
with lock:
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import threading
|
|
import eventlet
|
|
eventlet.monkey_patch()
|
|
test_lock = threading.RLock()
|
|
|
|
e1, e2 = threading.Event(), threading.Event()
|
|
a = eventlet.spawn(aaa, test_lock, e1, e2)
|
|
b = eventlet.spawn(bbb, test_lock, e1, e2)
|
|
a.wait()
|
|
b.wait()
|
|
print('pass')
|