【发布时间】:2018-07-26 04:21:24
【问题描述】:
我无法解决和理解这里的问题。我正在使用一个示例来学习 Asyncio,但我使用的代码与我的相似,但我的代码给出了一条错误消息:
sys:1: RuntimeWarning: coroutine 'run_script' 从未等待
任何帮助将不胜感激。下面是我的代码
async def run_script(script):
print("Run", script)
await asyncio.sleep(1)
os.system("python " + script)
我就是这样运行的
for script in os.listdir():
if script.endswith(".py"):
scripts.append(run_script(script))
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(scripts))
loop.close()
【问题讨论】:
-
传递给
gather时需要解压scripts:asyncio.gather(*scripts)。 -
感谢@dirn。现在可以使用了
标签: python python-asyncio coroutine