pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.67k stars 529 forks source link

Is it normal to have a bunch of warnings of "event doesn't exist" for parallel machines (with disjoint event sets)? #657

Closed enjoysmath closed 3 months ago

enjoysmath commented 5 months ago

Hi,

In the parallel example of transitions-gui, if you send model.event_on_A() and only model/machine A has the event, but the two machines are running in parallel, then a warning will be issued that B doesn't have any events from its current node that match "event_on_A". So just wondering if that is normal state of affairs, and I simply set logging level to ERROR-only.

I was unable to host the parallel machines on separate threads myself because of always getting that an event loop doesn't exist on my created thread, and was unable to SO-fix it. So the parallel + nested is the way to go for modeling the "whole system" or at least those parts we want expressed in FSM form. Therefore, the whole event queue internal of the Machine is shared among all the parallel processes.

Thanks.

EnjoysMath

aleneum commented 5 months ago

Hello @enjoysmath,

could you provide an MRE for your use case? As of now, if a state or transition includes a callback it is expected that all models that may enter that state also feature that callback. Defining def on_enter_<state> on one model is basically the same as calling <state>.add_callback("on_enter_<state>") directly.

I do see the value to resolve this dynamically for each model though but for now I'd say i'd suggest to work with protocols or such a like to make sure that all models implement the same callbacks.

aleneum commented 3 months ago

I am closing this since there hasn't been new feedback in (almost) 2 weeks. Feel free to comment if you still face this issue. I will reopen this issue if a bug or feature request emerges.