因此,基本上,在Python3.7中(据我所知),如果您try 这样做,
import asyncio
async def sleep():
asyncio.sleep(1)
async def main():
tasks = (sleep() for _ in range(5))
for task in asyncio.as_completed(tasks):
result = await task
if __name__ == "__main__":
asyncio.run(main())
它崩溃了,
TypeError: expect a list of futures, not generator
但类型提示明确指定它接受Iterable
,而Generator
则是.
如果你把tasks
分变成list
分,当然可以,但是...我遗漏了什么?
为什么它会受到名单的影响?我不明白为什么它不应该允许发电机.