asyncio atexit
Adds atexit functionality to asyncio:
import asyncio_atexit
async def close_db():
await db_connection.close()
asyncio_atexit.register(close_db)
atexit is part of the standard library,
and gives you a way to register functions to call when the interpreter exits.
asyncio doesn't have equivalent functionality to register functions
when the event loop exits:
This package adds functionality that can be considered equivalent to atexit.register
,
but tied to the event loop lifecycle. It:
- accepts both coroutines and synchronous functions
- should be called from a running event loop
- calls registered cleanup functions when the event loop closes
- only works if the application running the event loop calls
close()