def fetch_current_thread_functor():
"""Get the current thread.
If eventlet is used to monkey-patch the threading module, return the
current eventlet greenthread. Otherwise, return the current Python thread.
.. versionadded:: 1.5
"""
# Until https://github.com/eventlet/eventlet/issues/172 is resolved
# or addressed we have to use complicated workaround to get a object
# that will not be recycled; the usage of threading.current_thread()
# doesn't appear to currently be monkey patched and therefore isn't
# reliable to use (and breaks badly when used as all threads share
# the same current_thread() object)...
if not EVENTLET_AVAILABLE:
return threading.current_thread
else:
green_threaded = _patcher.is_monkey_patched('thread')
if green_threaded:
return _eventlet.getcurrent
else:
return threading.current_thread
评论列表
文章目录