When creating a child thread and calling pyppeteer, an error RuntimeError: There is no current event loop in thread'Thread-3' is reported.
pyppeteer startup code
loop = asyncio.get_event_loop()
loop.run_until_complete(main(name, password, keyword, isGetDefaultSKU)) # 将协程加入到事件循环loop
loop.close()
Solution
Change the code above to
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()
reference:
https://zhuanlan.zhihu.com/p/38575715
https://docs.python.org/zh-cn/3/library/asyncio-dev.html#concurrency-and-multithreading