admin管理员组

文章数量:1612097

使用异步操作:在程序里面执行threading时,会报下面的错误

There is no current event loop in thread ‘Thread-6’

这个说明在 thread-6的线程中没有事件循环,asyncio 中,先要创建一个 get_event_loop 的对象,然后需要生成一个类型是 list 的 tasks
最后把 tasks 放入 run 中进行循环处理。

将下面一句:

loop = asyncio.get_event_loop()

替换成下面两句即可

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

本文标签: 错误CurrentPythonasyniothread