【发布时间】:2018-02-10 21:45:21
【问题描述】:
我有一个调用异步循环的线程,但这会导致上述异常:
RuntimeError: There is no current event loop in thread 'Thread-1'.
这个问题:RuntimeError: There is no current event loop in thread in async + apscheduler 遇到了同样的问题,但是他们提到了我没有的调度程序。
我的代码如下:
def worker(ws):
l1 = asyncio.get_event_loop()
l1.run_until_complete(ws.start())
l2 = asyncio.get_event_loop()
l2.run_forever()
if __name__ == '__main__':
ws = Server()
p = threading.Thread(target=worker,args=(ws,))
p.start()
while True:
try:
#...do sth
except KeyboardInterrupt:
p.join()
exit()
【问题讨论】:
标签: python multithreading python-asyncio