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,7 +152,9 @@ def sqlite_timelimit(conn, ms):
return 1 return 1
conn.set_progress_handler(handler, n) conn.set_progress_handler(handler, n)
try:
yield yield
finally:
conn.set_progress_handler(None, n) conn.set_progress_handler(None, n)