From a314b761866d250c16f1ff6dd682010cf4181eb4 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 2 Oct 2019 08:32:47 -0700 Subject: [PATCH] Added /-/threads debugging page --- datasette/app.py | 13 +++++++++++++ docs/introspection.rst | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/datasette/app.py b/datasette/app.py index 501d1467..41a4eb37 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -457,6 +457,15 @@ class Datasette: for p in ps ] + def threads(self): + threads = list(threading.enumerate()) + return { + "num_threads": len(threads), + "threads": [ + {"name": t.name, "ident": t.ident, "daemon": t.daemon} for t in threads + ], + } + def table_metadata(self, database, table): "Fetch table-specific metadata." return ( @@ -621,6 +630,10 @@ class Datasette: JsonDataView.as_asgi(self, "config.json", lambda: self._config), r"/-/config(?P(\.json)?)$", ) + add_route( + JsonDataView.as_asgi(self, "threads.json", self.threads), + r"/-/threads(?P(\.json)?)$", + ) add_route( JsonDataView.as_asgi(self, "databases.json", self.connected_databases), r"/-/databases(?P(\.json)?)$", diff --git a/docs/introspection.rst b/docs/introspection.rst index e514ddf5..02552bab 100644 --- a/docs/introspection.rst +++ b/docs/introspection.rst @@ -90,6 +90,8 @@ Shows the :ref:`config` options for this instance of Datasette. `Config example "sql_time_limit_ms": 1000 } +.. _JsonDataView_databases: + /-/databases ------------ @@ -105,3 +107,26 @@ Shows currently attached databases. `Databases example `_:: + + { + "num_threads": 2, + "threads": [ + { + "daemon": false, + "ident": 4759197120, + "name": "MainThread" + }, + { + "daemon": true, + "ident": 123145319682048, + "name": "Thread-1" + }, + ] + }