hi, SQLAlchemy here -
an important feature that's needed for asyncio DBAPIs is the ability to close a database connection without an event loop being present. the most important need for this is cleanup routines that take place within Python garbage collection, such as weakref callbacks or __del__() methods. In the bigger scheme, the general issue of task cancellation in asyncio often leaves us in a spot where we've lost the event loop and need to close out a connection lest it remain open for the life of the process.
Since SQLAlchemy is a library, we're in a spot where if users don't have comprehensive handling of CancellationError everywhere it can possibly happen (a very large ask), connections can easily fall outside of the event loop and end up in the garbage collection phase. It's not something we can avoid entirely.
Of the asyncio dialects we support: asyncpg, psycopg, aiosqlite, asyncmy, aiomysql, aioodbc; oracledb seems to be the only one where there's not even a private means of doing this; just as an example, a terminate method looks like what you see in asyncpg here: https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.connection.Connection.terminate
hi, SQLAlchemy here -
an important feature that's needed for asyncio DBAPIs is the ability to close a database connection without an event loop being present. the most important need for this is cleanup routines that take place within Python garbage collection, such as weakref callbacks or
__del__()methods. In the bigger scheme, the general issue of task cancellation in asyncio often leaves us in a spot where we've lost the event loop and need to close out a connection lest it remain open for the life of the process.Since SQLAlchemy is a library, we're in a spot where if users don't have comprehensive handling of
CancellationErroreverywhere it can possibly happen (a very large ask), connections can easily fall outside of the event loop and end up in the garbage collection phase. It's not something we can avoid entirely.Of the asyncio dialects we support: asyncpg, psycopg, aiosqlite, asyncmy, aiomysql, aioodbc; oracledb seems to be the only one where there's not even a private means of doing this; just as an example, a terminate method looks like what you see in asyncpg here: https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.connection.Connection.terminate