Occasionally my Flask/WSGI application gets stuck while executing a query against an SQL Server database. I have no control over that server, so maybe I'll never be able to fix the issue, but at least I'd like to be able to present my users with a meaningful error message rather than a "500 Internal server error" caused by the web server's eventually giving up on the request. So I'd like to limit the SQL query execution to a reasonable timeout which, upon running out, would raise an exception which I could catch and deal with.
It seems the database query goes through several layers: SQLAlchemy -> PyODBC -> unixodbc -> MS ODBC Driver -> database. I have no idea which of those elements would be responsible for enforcing a query timeout, nor how to specify one. My connection URI looks like this:
mssql+pyodbc://user@host/db?driver=ODBC+Driver+17+for+SQL+Server
I don't need to specify a per-query timeout. Just once for the whole application.
Thanks!