-
-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Labels
Milestone
Description
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 |
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.- There is no public API for the parent to send events to a running child machine.
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.- No public API on
StateChart—send_to_child()exists onInvokeManagerbut is internal (sm._engine._invoke_manager). There's no user-facing method. - Invoke ID not exposed — users have no way to obtain the
invokeidof a running invocation (SCXML usesidlocation=for this).
Possible approach
- Add
on_event()toStateChartInvokerthat forwards toself._child.send(). - Pass
_invoke_sessionwhen instantiating Python child machines so they can send events to the parent. - Expose a public method on
StateChartfor parent → child communication (e.g.,sm.send_to_invoke(invokeid, event, **data)). - Consider an
autoforwardoption forState(invoke=..., autoforward=True).
Reactions are currently unavailable