Workaround for test failure: RuntimeError: There is no current event loop (#1803)

* Remove ensure_eventloop hack
* Hack to recover from intermittent RuntimeError calling asyncio.Lock()
This commit is contained in:
Simon Willison 2022-09-05 17:40:19 -07:00 committed by GitHub
commit 64288d827f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View file

@ -231,7 +231,15 @@ class Datasette:
self.inspect_data = inspect_data
self.immutables = set(immutables or [])
self.databases = collections.OrderedDict()
self._refresh_schemas_lock = asyncio.Lock()
try:
self._refresh_schemas_lock = asyncio.Lock()
except RuntimeError as rex:
# Workaround for intermittent test failure, see:
# https://github.com/simonw/datasette/issues/1802
if "There is no current event loop in thread" in str(rex):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
self._refresh_schemas_lock = asyncio.Lock()
self.crossdb = crossdb
self.nolock = nolock
if memory or crossdb or not self.files: