-
-
Notifications
You must be signed in to change notification settings - Fork 778
Closed
Labels
Milestone
Description
datasette/datasette/utils/__init__.py
Lines 181 to 200 in 1a7750e
@contextmanager | |
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 | |
n = 1000 | |
if ms < 50: | |
n = 1 | |
def handler(): | |
if time.perf_counter() >= deadline: | |
return 1 | |
conn.set_progress_handler(handler, n) | |
try: | |
yield | |
finally: | |
conn.set_progress_handler(None, n) |
@contextmanager
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
n = 1000
if ms < 50:
n = 1
def handler():
if time.perf_counter() >= deadline:
return 1
conn.set_progress_handler(handler, n)
try:
yield
finally:
conn.set_progress_handler(None, n)
How often do I set a time limit of 50 or less? How much slower does it go thanks to this code?