"Marko Rauhamaa"  wrote in message news:8737t5shhp....@elektro.pacujo.net...
>
Actually, cancellation is specially supported in asyncio (<URL:
https://docs.python.org/3/library/asyncio-task.html#asyncio.Task.cancel>)
so this should do:

    async def background_task():
        while True:
            await perform_task()
            await asyncio.sleep(10)


That's exactly what I needed - thanks, Marko

   async def background_task()
       try:
           while True:
               await perform_task()
               await asyncio.sleep(10)
       except asyncio.CancelledError:
               await perform_cleanup()

At startup -

   task = asyncio.ensure_future(background_task())

At shutdown -

   task.cancel()
   await asyncio.wait([task])

Works perfectly - thanks again.

Frank


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to