在子线程内直接获取事件循环会报错:RuntimeError: There is no current event loop in thread 'Thread-2',此时的代码为:
loop = asyncio.get_event_loop()
loop.run_until_complete(协程函数) # 执行
解决方法:
在子线程内创建并配置事件循环
new_loop = asyncio.new_event_loop() # 子线程下新建时间循环标签:协程,Thread,thread,RuntimeError,线程,event,loop,asyncio From: https://www.cnblogs.com/CJTARRR/p/17604060.html
asyncio.set_event_loop(new_loop) # 配置新建的事件循环
loop = asyncio.get_event_loop()
loop.run_until_complete(协程函数) # 执行