mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.88k stars 562 forks source link

Allow us to change the cursor's timeout #1217

Open hb2638 opened 1 year ago

hb2638 commented 1 year ago

Please first make sure you have looked at:

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

Issue

The cursor's SQL_ATTR_QUERY_TIMEOUT gets applied when the cursor is instaniated and it uses whatever timeout the connection has at that time... ok. But the problem is there's no way to change this. I thought changing the connection's timeout would do it but that's not the case after looking at the source code.

I'm running stuff inside AWS lambda and I want to the timeout to be a few seconds less than the "remaining execution time". Lambda lets you run for up to 15 minutes, so I want my query time to be reflective of the remaining time.

Is there at least a workaround where I can call SQLSetStmtAttr with SQL_ATTR_QUERY_TIMEOUT on the cursor object from python?

v-chojas commented 1 year ago

Must you use same cursor object, or is it acceptable to recreate it?

hb2638 commented 1 year ago

I think I can get away with recreating.