|
3 | 3 | from eventlet.support import greenlets as greenlet, six |
4 | 4 | from eventlet import greenthread |
5 | 5 | from eventlet.semaphore import Semaphore as LockType |
| 6 | +import sys |
6 | 7 |
|
7 | 8 |
|
8 | 9 | __patched__ = ['get_ident', 'start_new_thread', 'start_new', 'allocate_lock', |
@@ -43,6 +44,19 @@ def __thread_body(func, args, kwargs): |
43 | 44 |
|
44 | 45 |
|
45 | 46 | def start_new_thread(function, args=(), kwargs=None): |
| 47 | + if (sys.version_info >= (3, 4) |
| 48 | + and getattr(function, '__module__', '') == 'threading' |
| 49 | + and hasattr(function, '__self__')): |
| 50 | + # Since Python 3.4, threading.Thread uses an internal lock |
| 51 | + # automatically released when the python thread state is deleted. |
| 52 | + # With monkey patching, eventlet uses green threads without python |
| 53 | + # thread state, so the lock is not automatically released. |
| 54 | + # |
| 55 | + # Disable the thread state lock to avoid dead locks. |
| 56 | + thread = function.__self__ |
| 57 | + thread._set_tstate_lock = lambda: None |
| 58 | + thread._wait_for_tstate_lock = lambda *args, **kw: None |
| 59 | + |
46 | 60 | kwargs = kwargs or {} |
47 | 61 | g = greenthread.spawn_n(__thread_body, function, args, kwargs) |
48 | 62 | return get_ident(g) |
|
0 commit comments