Skip to content

Commit

Permalink
Drop n=1 threshold down to <= 20ms, closes #1679
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Mar 21, 2022
1 parent 1a7750e commit 72bfd75
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions datasette/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ def default(self, obj):
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)
Expand Down

0 comments on commit 72bfd75

Please sign in to comment.