Skip to content

Commit 390e71d

Browse files
haypoenovancetemoto
authored andcommitted
Disable the thread state lock
1 parent b5bfe1c commit 390e71d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

eventlet/green/thread.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from eventlet.support import greenlets as greenlet, six
44
from eventlet import greenthread
55
from eventlet.semaphore import Semaphore as LockType
6+
import sys
67

78

89
__patched__ = ['get_ident', 'start_new_thread', 'start_new', 'allocate_lock',
@@ -43,6 +44,19 @@ def __thread_body(func, args, kwargs):
4344

4445

4546
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+
4660
kwargs = kwargs or {}
4761
g = greenthread.spawn_n(__thread_body, function, args, kwargs)
4862
return get_ident(g)

0 commit comments

Comments
 (0)