Summary
When using <invoke> via SCXML, parent and child state machines can exchange events using <send target="#_parent"> (child → parent) and <send target="#_<invokeid>"> (parent → child). This communication protocol is not yet available when defining state machines in Python.
Current state
| Direction |
SCXML |
Python (IInvoke) |
Python (callable / StateChart) |
| Parent → Child |
<send target="#_<invokeid>"> |
No |
No |
| Child → Parent |
<send target="#_parent"> |
ctx.send() |
No |
IInvoke handlers can send events to the parent via ctx.send(), but plain callables, naming convention methods (on_invoke_<state>), and child StateChart classes have no way to communicate back.
- There is no public API for the parent to send events to a running child machine.
Gaps
StateChartInvoker lacks on_event() — InvokeManager.send_to_child() requires the handler to implement on_event(event, **data), but StateChartInvoker (used for State(invoke=ChildMachine)) doesn't have it.
_invoke_session not set for Python children — StateChartInvoker.run() instantiates the child without passing _invoke_session, so the child has no reference to the parent. Only SCXMLInvoker sets this up.
- No public API on
StateChart — send_to_child() exists on InvokeManager but is internal (sm._engine._invoke_manager). There's no user-facing method.
- Invoke ID not exposed — users have no way to obtain the
invokeid of a running invocation (SCXML uses idlocation= for this).
Possible approach
- Add
on_event() to StateChartInvoker that forwards to self._child.send().
- Pass
_invoke_session when instantiating Python child machines so they can send events to the parent.
- Expose a public method on
StateChart for parent → child communication (e.g., sm.send_to_invoke(invokeid, event, **data)).
- Consider an
autoforward option for State(invoke=..., autoforward=True).
Summary
When using
<invoke>via SCXML, parent and child state machines can exchange events using<send target="#_parent">(child → parent) and<send target="#_<invokeid>">(parent → child). This communication protocol is not yet available when defining state machines in Python.Current state
IInvoke)StateChart)<send target="#_<invokeid>"><send target="#_parent">ctx.send()IInvokehandlers can send events to the parent viactx.send(), but plain callables, naming convention methods (on_invoke_<state>), and childStateChartclasses have no way to communicate back.Gaps
StateChartInvokerlackson_event()—InvokeManager.send_to_child()requires the handler to implementon_event(event, **data), butStateChartInvoker(used forState(invoke=ChildMachine)) doesn't have it._invoke_sessionnot set for Python children —StateChartInvoker.run()instantiates the child without passing_invoke_session, so the child has no reference to the parent. OnlySCXMLInvokersets this up.StateChart—send_to_child()exists onInvokeManagerbut is internal (sm._engine._invoke_manager). There's no user-facing method.invokeidof a running invocation (SCXML usesidlocation=for this).Possible approach
on_event()toStateChartInvokerthat forwards toself._child.send()._invoke_sessionwhen instantiating Python child machines so they can send events to the parent.StateChartfor parent → child communication (e.g.,sm.send_to_invoke(invokeid, event, **data)).autoforwardoption forState(invoke=..., autoforward=True).