gpt4 book ai didi

python - "Asyncio Event Loop is Closed"获取循环时

转载 作者:IT老高 更新时间:2023-10-28 22:14:46 32 4
gpt4 key购买 nike

当尝试运行文档中给出的 asyncio hello world 代码示例时:

import asyncio

async def hello_world():
print("Hello World!")

loop = asyncio.get_event_loop()
# Blocking call which returns when the hello_world() coroutine is done
loop.run_until_complete(hello_world())
loop.close()

我得到错误:

RuntimeError: Event loop is closed

我正在使用 python 3.5.3。

最佳答案

在 Windows 上似乎是 EventLoopPolicy 的问题,使用此代码段解决它:

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())

关于python - "Asyncio Event Loop is Closed"获取循环时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45600579/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com