Expand description
The centralized Tokio runtime for a running Nautilus system.
§Design rationale
NautilusTrader uses a single global Tokio runtime because:
- A single long-lived runtime avoids repeated startup/shutdown overhead.
- The runtime is lazily initialized on first call to
get_runtime()viaOnceLock. - Worker thread count is configurable via the
NAUTILUS_WORKER_THREADSenvironment variable.
§Python support
When the python feature is enabled, the runtime initializes the Python interpreter
before starting worker threads. The PyO3 module registers an atexit handler via
shutdown_runtime() to cleanly shut down when Python exits.
§Testing considerations
The global runtime pattern makes it harder to inject test doubles. For testing:
- Unit tests can use
#[tokio::test]which creates its own runtime. - Integration tests should be aware they share the global runtime state.
Functions§
- get_
runtime - Returns a reference to the global Nautilus Tokio runtime.
- shutdown_
runtime - Provides a best-effort flush for runtime tasks during shutdown.