Added /-/threads debugging page

This commit is contained in:
Simon Willison 2019-10-02 08:32:47 -07:00
commit a314b76186
2 changed files with 38 additions and 0 deletions

View file

@ -457,6 +457,15 @@ class Datasette:
for p in ps 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): def table_metadata(self, database, table):
"Fetch table-specific metadata." "Fetch table-specific metadata."
return ( return (
@ -621,6 +630,10 @@ class Datasette:
JsonDataView.as_asgi(self, "config.json", lambda: self._config), JsonDataView.as_asgi(self, "config.json", lambda: self._config),
r"/-/config(?P<as_format>(\.json)?)$", r"/-/config(?P<as_format>(\.json)?)$",
) )
add_route(
JsonDataView.as_asgi(self, "threads.json", self.threads),
r"/-/threads(?P<as_format>(\.json)?)$",
)
add_route( add_route(
JsonDataView.as_asgi(self, "databases.json", self.connected_databases), JsonDataView.as_asgi(self, "databases.json", self.connected_databases),
r"/-/databases(?P<as_format>(\.json)?)$", r"/-/databases(?P<as_format>(\.json)?)$",

View file

@ -90,6 +90,8 @@ Shows the :ref:`config` options for this instance of Datasette. `Config example
"sql_time_limit_ms": 1000 "sql_time_limit_ms": 1000
} }
.. _JsonDataView_databases:
/-/databases /-/databases
------------ ------------
@ -105,3 +107,26 @@ Shows currently attached databases. `Databases example <https://latest.datasette
"size": 225280 "size": 225280
} }
] ]
.. _JsonDataView_threads:
/-/threads
----------
Shows details of threads. `Threads example <https://latest.datasette.io/-/threads>`_::
{
"num_threads": 2,
"threads": [
{
"daemon": false,
"ident": 4759197120,
"name": "MainThread"
},
{
"daemon": true,
"ident": 123145319682048,
"name": "Thread-1"
},
]
}