pyppeteer 异常 RuntimeError: There is no current event loop in thread ‘Thread-3‘.

创建子线程 调用pyppeteer时 报错 RuntimeError: There is no current event loop in thread 'Thread-3'.

 

 pyppeteer启动代码

loop = asyncio.get_event_loop()
loop.run_until_complete(main(name, password, keyword, isGetDefaultSKU))  # 将协程加入到事件循环loop
loop.close()

 解决办法

将上边的代码改为


loop1 = asyncio.new_event_loop() 
asyncio.set_event_loop(loop1)
loop = asyncio.get_event_loop()
loop.run_until_complete(main(name, password, keyword, isGetDefaultSKU))  # 将协程加入到事件循环loop
loop.close()

参考:

https://binglau7.github.io/2018/01/30/%E5%85%B3%E4%BA%8E-asyncio-%E7%9A%84%E5%96%83%E5%96%83%E8%87%AA%E8%AF%AD/

https://zhuanlan.zhihu.com/p/38575715

https://docs.python.org/zh-cn/3/library/asyncio-dev.html#concurrency-and-multithreading

猜你喜欢

转载自blog.csdn.net/weixin_41822224/article/details/107490323
今日推荐