asyncio.wait_for cancels my task but the cleanup hangs for 8 seconds
Python 3.12. I use await asyncio.wait_for(do_stuff(), timeout=5). When it times out I get the TimeoutError as expected, but my finally block in do_stuff has an await cleanup() that itself takes about 8 seconds, and wait_for doesn't return until that finishes. So my 5 second timeout actually takes 13 seconds. Is there a way to give up without waiting for cleanup? I don't think I want to shield it but I'm not sure.
4 replies