import asyncio
import aiojobs
async def coro(timeout):
print(timeout)
await asyncio.sleep(timeout)
print(">>>>>>>")
async def main():
scheduler = await aiojobs.create_scheduler()
for i in range(1,100):
# spawn jobs
await scheduler.spawn(coro(i/10))
await asyncio.sleep(4)
# 并不是所以的工作完成
# 优雅的结束
await scheduler.close()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
转载于:https://www.cnblogs.com/c-x-a/p/10572377.html
相关资源:fastapi-plugins:FastAPI框架插件-源码