Added /-/threads debugging page

pull/589/head
Simon Willison 2019-10-02 08:32:47 -07:00
rodzic 0fc8afde0e
commit a314b76186
2 zmienionych plików z 38 dodań i 0 usunięć

Wyświetl plik

@ -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<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "threads.json", self.threads),
r"/-/threads(?P<as_format>(\.json)?)$",
)
add_route(
JsonDataView.as_asgi(self, "databases.json", self.connected_databases),
r"/-/databases(?P<as_format>(\.json)?)$",

Wyświetl plik

@ -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 <https://latest.datasette
"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"
},
]
}