nautechsystems/nautilus_trader · error
Python on_start failed: {e}
Error message
Python on_start failed: {e} What it means
PyExecutionAlgorithm implements the DataActor lifecycle. Its on_start first runs the Rust-side ExecutionAlgorithm::on_start, then dispatches the Python `on_start` callback; a Python-side exception is re-wrapped with this message. It indicates the Python component failed to start.
Source
Thrown at crates/trading/src/python/algorithm.rs:547
let _ = self
.dispatch_position_event("on_position_changed", PositionEvent::PositionChanged(event));
}
fn on_position_closed(&mut self, event: PositionClosed) {
let _ = self
.dispatch_position_event("on_position_closed", PositionEvent::PositionClosed(event));
}
fn on_position_event(&mut self, event: PositionEvent) {
let _ = self.dispatch_position_event("on_position_event", event);
}
}
impl DataActor for PyExecutionAlgorithm {
fn on_start(&mut self) -> anyhow::Result<()> {
ExecutionAlgorithm::on_start(self)?;
self.dispatch_no_args("on_start")
.map_err(|e| anyhow::anyhow!("Python on_start failed: {e}"))
}
fn on_stop(&mut self) -> anyhow::Result<()> {
ExecutionAlgorithm::on_stop(self)?;
self.dispatch_no_args("on_stop")
.map_err(|e| anyhow::anyhow!("Python on_stop failed: {e}"))
}
fn on_resume(&mut self) -> anyhow::Result<()> {
ExecutionAlgorithm::on_resume(self)?;
self.dispatch_no_args("on_resume")
.map_err(|e| anyhow::anyhow!("Python on_resume failed: {e}"))
}
fn on_reset(&mut self) -> anyhow::Result<()> {
ExecutionAlgorithm::on_reset(self)?;
self.dispatch_no_args("on_reset")
.map_err(|e| anyhow::anyhow!("Python on_reset failed: {e}"))View on GitHub (pinned to 18893faf8b)
Solutions
- Read the chained `{e}` traceback and fix the Python on_start callback.
- Ensure any external resources the callback needs (connections, config) are available before start.
- Call on_reset (or fresh construction) before restarting so stale state cannot break startup.
- Confirm the Python class defines a zero-argument on_start method.
Example fix
// before def on_start(self, config): ... # unexpected argument // after def on_start(self): ...
Defensive patterns
Strategy: try-catch
Validate before calling
# Python: preflight startup dependencies before the engine starts assert self.ready, "state not initialized; call __init__/on_reset first"
Try / catch
match actor.on_start() {
Ok(()) => {},
Err(e) => {
log::error!("python on_start failed: {e:#}");
// route the actor to faulted state instead of continuing
}
} Prevention
- Validate external dependencies (connections, config) in on_start and fail fast with clear messages.
- Always run on_reset (or fresh construction) before a restart.
- Keep lifecycle hooks zero-argument as the DataActor contract requires.
When it happens
Trigger: Calling on_start when the Python on_start raises — e.g. failed initialization inside the user callback, resources unavailable at start, or invalid no-arg dispatch.
Common situations: Python on_start connecting to external services that are down; referencing attributes initialized in an overridden __init__ that was not called; state carried over from a previous run without reset.
Related errors
- Python on_stop failed: {e}
- Python on_resume failed: {e}
- Python on_reset failed: {e}
- Python on_dispose failed: {e}
- Python on_degrade failed: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/f3b55d5655dde59a.
Report an issue: GitHub.