Drop n=1 threshold down to <= 20ms, closes #1679

pull/1685/head
Simon Willison 2022-03-21 14:55:50 -07:00
rodzic 1a7750eb29
commit 72bfd75fb7
1 zmienionych plików z 5 dodań i 4 usunięć

Wyświetl plik

@ -182,15 +182,16 @@ class CustomJSONEncoder(json.JSONEncoder):
def sqlite_timelimit(conn, ms):
deadline = time.perf_counter() + (ms / 1000)
# n is the number of SQLite virtual machine instructions that will be
# executed between each check. It's hard to know what to pick here.
# After some experimentation, I've decided to go with 1000 by default and
# 1 for time limits that are less than 50ms
# executed between each check. It takes about 0.08ms to execute 1000.
# https://github.com/simonw/datasette/issues/1679
n = 1000
if ms < 50:
if ms <= 20:
# This mainly happens while executing our test suite
n = 1
def handler():
if time.perf_counter() >= deadline:
# Returning 1 terminates the query with an error
return 1
conn.set_progress_handler(handler, n)