Ensure sqlite_timelimit correctly clears handler

If an error occurred inside the block the progress handler (used to
enforce a time limit) was not being correctly cleared, resulting in
timeout errors potentially occurring during subsequent SQL queries.

The fix is described here: https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager
This commit is contained in:
Simon Willison 2019-04-21 12:02:24 -07:00
commit bac4e01f40

View file

@ -152,8 +152,10 @@ def sqlite_timelimit(conn, ms):
return 1
conn.set_progress_handler(handler, n)
yield
conn.set_progress_handler(None, n)
try:
yield
finally:
conn.set_progress_handler(None, n)
class InvalidSql(Exception):