【发布时间】:2019-04-12 17:18:35
【问题描述】:
为什么 asyncio (source) 中的 get_event_loop 方法正在检查当前线程是否是主线程(请参阅下面 sn-p 中的评论)?
def get_event_loop(self):
"""Get the event loop.
This may be None or an instance of EventLoop.
"""
if (self._local._loop is None and
not self._local._set_called and
isinstance(threading.current_thread(), threading._MainThread)): # <- I mean this thing here
self.set_event_loop(self.new_event_loop())
if self._local._loop is None:
raise RuntimeError('There is no current event loop in thread %r.'
% threading.current_thread().name)
return self._local._loop
【问题讨论】:
标签: python multithreading python-asyncio