mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Run scan_dirs() in a thread
This commit is contained in:
parent
6ff261c1de
commit
55e633e09f
2 changed files with 6 additions and 6 deletions
|
|
@ -186,7 +186,8 @@ class Datasette:
|
||||||
if db.name in self.databases:
|
if db.name in self.databases:
|
||||||
raise Exception("Multiple files with same stem: {}".format(db.name))
|
raise Exception("Multiple files with same stem: {}".format(db.name))
|
||||||
self.add_database(db.name, db)
|
self.add_database(db.name, db)
|
||||||
self.scan_dirs()
|
self.scan_dirs_executor = futures.ThreadPoolExecutor(max_workers=1)
|
||||||
|
self.scan_dirs_executor.submit(self.scan_dirs)
|
||||||
self.cache_headers = cache_headers
|
self.cache_headers = cache_headers
|
||||||
self.cors = cors
|
self.cors = cors
|
||||||
self._metadata = metadata or {}
|
self._metadata = metadata or {}
|
||||||
|
|
@ -224,7 +225,6 @@ class Datasette:
|
||||||
|
|
||||||
def scan_dirs(self):
|
def scan_dirs(self):
|
||||||
# Recurse through self.dirs looking for new SQLite DBs
|
# Recurse through self.dirs looking for new SQLite DBs
|
||||||
i = 0
|
|
||||||
for dir in self.dirs:
|
for dir in self.dirs:
|
||||||
print(dir)
|
print(dir)
|
||||||
for filepath in Path(dir).glob("**/*.db"):
|
for filepath in Path(dir).glob("**/*.db"):
|
||||||
|
|
@ -237,9 +237,6 @@ class Datasette:
|
||||||
.replace(".db", ""),
|
.replace(".db", ""),
|
||||||
Database(self, filepath, is_mutable=True),
|
Database(self, filepath, is_mutable=True),
|
||||||
)
|
)
|
||||||
i += 1
|
|
||||||
if i >= 20:
|
|
||||||
break
|
|
||||||
|
|
||||||
def config(self, key):
|
def config(self, key):
|
||||||
return self._config.get(key, None)
|
return self._config.get(key, None)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,10 @@ class IndexView(BaseView):
|
||||||
|
|
||||||
async def get(self, request, as_format):
|
async def get(self, request, as_format):
|
||||||
databases = []
|
databases = []
|
||||||
for name, db in self.ds.databases.items():
|
# Using list() here because scan_dirs() running in a thread might
|
||||||
|
# modify self.ds.databases while we are iterating it, which could
|
||||||
|
# cause 'RuntimeError: OrderedDict mutated during iteration'
|
||||||
|
for name, db in list(self.ds.databases.items()):
|
||||||
table_names = await db.table_names()
|
table_names = await db.table_names()
|
||||||
hidden_table_names = set(await db.hidden_table_names())
|
hidden_table_names = set(await db.hidden_table_names())
|
||||||
views = await db.view_names()
|
views = await db.view_names()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue