我正在尝试使用 asyncio.create_subprocess_exec 启动一堆子进程:
procs = []
for i in range(5):
proc = await asyncio.create_subprocess_exec(...)
procs.append(proc.wait())
# doesn't work with this line either:
procs.append(asyncio.create_task(proc.wait()))
await asyncio.wait(*procs,..)
# doesn't work with await asyncio.as_completed either. asyncio.gather do work, but I'd like to add timeout limit and return back to my code as earlier as possible.
例外是:TypeError: expect a list of futures, not Task against line 'await asyncio.wait(*procs,..) Python 的版本是 3.8。
尽管在官方文档中警告不要自己创建未来,但如果有办法将proc转换为 Future,我想尝试一下。
喵喔喔
相关分类