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:
Victor Stinner
2015-01-06 17:09:23 +01:00
committed by Sergey Shepelev
parent 4f3eaa0f54
commit b5bfe1cad9
3 changed files with 34 additions and 0 deletions

View File

@@ -304,6 +304,13 @@ def monkey_patch(**on):
# importlib must use real thread locks, not eventlet.Semaphore
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):
"""Returns True if the given module is monkeypatched currently, False if

View 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')

View File

@@ -498,3 +498,7 @@ t2.join()
def test_importlib_lock():
tests.run_isolated('patcher_importlib_lock.py')
def test_threading_condition():
tests.run_isolated('patcher_threading_condition.py')