Skip to main content

shutdown_tokio_runtime

Function shutdown_tokio_runtime 

Source
pub fn shutdown_tokio_runtime(py: Python<'_>)
Expand description

atexit handler that tears down the global Tokio runtime.

Callers obtain a cloned Handle from get_tokio_runtime() rather than a guard, so the runtime mutex is uncontended at shutdown. We can take ownership of the Runtime and call shutdown_timeout directly. If a worker thread is still inside Handle::block_on on a future that never resolves (e.g. a non-main thread that cannot observe SIGINT), shutdown_timeout aborts spawned tasks and returns after at most one second; the stuck worker is then a daemon thread that CPython kills on interpreter exit.