python - Asyncio: keep multiple coroutines running -
i have multiple coroutines need running (forever) @ same time. error handling 1 of routines ends , needs respawned , use following code, assumes coroutine1 needs restarting.
pending = {coroutine1(), coroutine2()} while true: = asyncio.wait(pending, return_when=asyncio.first_completed) done, pending = loop.run_until_complete(a) pending = pending | {coroutine1()}
how can solve in better , more general way?
what using different approach?
async def run_forever(corofn): while true: await corofn() corofns = coroutine1, coroutine2 await asyncio.wait(map(run_forever, corofns))
Comments
Post a Comment