{"record":{"id":"0f2164d12d492545","repo":"nautechsystems/nautilus_trader","slug":"python-on-signal-failed-e","errorCode":null,"errorMessage":"Python on_signal failed: {e}","messagePattern":"Python on_signal failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1079,"sourceCode":"    }\n\n    fn on_time_event(&mut self, event: &TimeEvent) -> anyhow::Result<()> {\n        self.dispatch_on_time_event(event.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_time_event failed: {e}\"))\n    }\n\n    #[allow(unused_variables)]\n    fn on_data(&mut self, data: &CustomData) -> anyhow::Result<()> {\n        Python::attach(|py| {\n            let py_data: Py<PyAny> = Py::new(py, data.clone())?.into_any();\n            self.dispatch_on_data(py_data)\n                .map_err(|e| anyhow::anyhow!(\"Python on_data failed: {e}\"))\n        })\n    }\n\n    fn on_signal(&mut self, signal: &Signal) -> anyhow::Result<()> {\n        self.dispatch_on_signal(signal)\n            .map_err(|e| anyhow::anyhow!(\"Python on_signal failed: {e}\"))\n    }\n\n    fn on_queue_state(&mut self, event: &QueueStateChanged) -> anyhow::Result<()> {\n        self.dispatch_on_queue_state(event)\n            .map_err(|e| anyhow::anyhow!(\"Python on_queue_state failed: {e}\"))\n    }\n\n    fn on_socket_state(&mut self, event: &SocketStateChanged) -> anyhow::Result<()> {\n        self.dispatch_on_socket_state(event)\n            .map_err(|e| anyhow::anyhow!(\"Python on_socket_state failed: {e}\"))\n    }\n\n    fn on_instrument(&mut self, instrument: &InstrumentAny) -> anyhow::Result<()> {\n        Python::attach(|py| {\n            let py_instrument = instrument_any_to_pyobject(py, instrument.clone())\n                .map_err(|e| anyhow::anyhow!(\"Failed to convert InstrumentAny to Python: {e}\"))?;\n            self.dispatch_on_instrument(py_instrument)\n                .map_err(|e| anyhow::anyhow!(\"Python on_instrument failed: {e}\"))","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1061-L1097","documentation":"This error wraps any failure raised while the Rust core dispatches the `on_signal` handler of a Python actor/strategy into its Python implementation. The Rust side called `dispatch_on_signal`, the Python `on_signal` method (or the GIL/dispatch machinery around it) raised, and Rust re-raises it as an anyhow error prefixed with 'Python on_signal failed'. It means the user's Python handler code itself failed, not the signal data transport.","triggerScenarios":"A Signal arrives (subscribe_signal was used) and the user's Python `on_signal(self, signal)` override raises an exception, or the dispatch into Python fails (e.g. the handler is not callable or the GIL callback errors).","commonSituations":"User `on_signal` overrides referencing attributes not yet initialized, typos in the handler signature, raising inside signal-handling logic such as order submission on signal, or a bug in the Python class registered with the trader.","solutions":["Read the chained `{e}` message to find the original Python traceback and fix the exception raised inside your `on_signal` override","Verify your `on_signal(self, signal)` signature matches what the actor dispatches (single Signal argument)","Guard the handler body with try/except during development and log the full traceback","Confirm the actor was fully initialized/registered before signals can arrive"],"exampleFix":"// before\ndef on_signal(self, signal):\n    self.orders.submit(...)  # raises if self.orders is None\n// after\ndef on_signal(self, signal):\n    if self.orders is None:\n        self.log.warning('orders not ready')\n        return\n    self.orders.submit(...)","handlingStrategy":"try-catch","validationCode":"def _check_on_signal(self, signal):\n    assert callable(getattr(self, 'on_signal', None)), 'on_signal not defined'\n    try:\n        self.on_signal(signal)\n    except Exception as e:\n        self.log.error(f'on_signal failed: {e!r}')","typeGuard":null,"tryCatchPattern":"try:\n    self.dispatch_on_signal(signal)\nexcept Exception as e:\n    self.log.error(f'Python on_signal failed: {e}', exc_info=True)","preventionTips":["Keep on_signal handlers small and wrap risky logic in try/except with logging","Test signal handlers in a backtest run before live deployment","Match the exact handler signature expected by the actor dispatch"],"tags":["python","actor","callback","rust-binding"],"backgroundTag":"python-callback-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}