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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -