Fix threading.Condition with monkey-patching
For the Python implementation of threading.RLock because the new C implementation of threading.RLock of Python 3.3 is not compatible with eventlet monkey patching. Fix the issue #185.
This commit is contained in:

committed by
Sergey Shepelev

parent
4f3eaa0f54
commit
b5bfe1cad9
@@ -304,6 +304,13 @@ def monkey_patch(**on):
|
|||||||
# importlib must use real thread locks, not eventlet.Semaphore
|
# importlib must use real thread locks, not eventlet.Semaphore
|
||||||
importlib._bootstrap._thread = thread
|
importlib._bootstrap._thread = thread
|
||||||
|
|
||||||
|
# Issue #185: Since Python 3.3, threading.RLock is implemented in C and
|
||||||
|
# so call a C function to get the thread identifier, instead of calling
|
||||||
|
# threading.get_ident(). Force the Python implementation of RLock which
|
||||||
|
# calls threading.get_ident() and so is compatible with eventlet.
|
||||||
|
import threading
|
||||||
|
threading.RLock = threading._PyRLock
|
||||||
|
|
||||||
|
|
||||||
def is_monkey_patched(module):
|
def is_monkey_patched(module):
|
||||||
"""Returns True if the given module is monkeypatched currently, False if
|
"""Returns True if the given module is monkeypatched currently, False if
|
||||||
|
23
tests/isolated/patcher_threading_condition.py
Normal file
23
tests/isolated/patcher_threading_condition.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Issue #185: test threading.Condition with monkey-patching
|
||||||
|
import eventlet
|
||||||
|
|
||||||
|
# no standard tests in this file, ignore
|
||||||
|
__test__ = False
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
eventlet.monkey_patch()
|
||||||
|
|
||||||
|
import threading
|
||||||
|
|
||||||
|
def func(c):
|
||||||
|
with c:
|
||||||
|
c.notify()
|
||||||
|
|
||||||
|
c = threading.Condition()
|
||||||
|
with c:
|
||||||
|
t = threading.Thread(target=func, args=(c,))
|
||||||
|
t.start()
|
||||||
|
c.wait()
|
||||||
|
|
||||||
|
print('pass')
|
@@ -498,3 +498,7 @@ t2.join()
|
|||||||
|
|
||||||
def test_importlib_lock():
|
def test_importlib_lock():
|
||||||
tests.run_isolated('patcher_importlib_lock.py')
|
tests.run_isolated('patcher_importlib_lock.py')
|
||||||
|
|
||||||
|
|
||||||
|
def test_threading_condition():
|
||||||
|
tests.run_isolated('patcher_threading_condition.py')
|
||||||
|
Reference in New Issue
Block a user