Hi!
Sorry for bothering, I have not enough skills to contribute yet (
But...
I think it would be great to have some feature to easily set connection timeouts in SQLAlchemy 2.0.
The reason is I faced a problem where I was unable to cancel some erroneous time-consuming queries with SQLAlchemy Core. And I guess, I am not the only one.
My straightforward nooby solution so far is this:
from threading import Timer
with engine.connect() as connection:
timeout = Timer(MAX_EXECUTION_TIME, lambda: connection.connection.connection.cancel())
timeout.start()
r = connection.execute(stmt).freeze() # I just love FrozenResult)
timeout.cancel()
The bad thing this is dialect-specific and works only due to cancel() method in psycopg2
I was also trying to benefit from handling sqlalchemy.events but failed...
One of my intentions was to modify before_execute() method to catch unintended cartesian product queries and raise error instead of throwing warning.
Unfortunately, at the moment this feels like too low-level for me.
What I wish to have is something like this:
with engine.connect(timeout=MAX_EXECUTION_TIME) as connection:
r = connection.execute(stmt)
I hope somebody smart enough could seize time to think about it.
This would make me happy.
Thanks in advance!