nradulovic / pyeds

Python Event Driven System
GNU Lesser General Public License v3.0
11 stars 4 forks source link

Hang on direct state transition? #17

Open dclementson opened 3 years ago

dclementson commented 3 years ago

Hi Nenad:

I'm finding that pyeds hangs if I ask a FSM to transition directly from one state to another without having an Event trigger the transition. Here is an example of a FSM that I thought would go directly from the "Run" state to the "Idle" state after first printing a message. It hangs at the "return Idle" statement:

`@fsm.DeclareState(myFSM) class Run(fsm.State):

def on_entry(self):
    print('Run state going to Idle state')
    return Idle`

this example does essentially the same transition logic, but does not hang:

`@fsm.DeclareState(myFSM) class Run(fsm.State):

def on_entry(self):
    print(Run state going to Idle state')
    fsm.After(0.1, 'delay')

def on_delay(self, event):
    return Idle`

Is this the expected behavior or am I missing something? Thanks! DC

nradulovic commented 3 years ago

Hello DC

Let me check, but I think it is invalid to invoke transition from on_entry in a state.

nradulovic commented 3 years ago

Hello DC,

Event less transitions are not allowed on PyEDS. That means that on_entry and on_exitdoes not support taking a transition. This brings up two things:

  1. This behavior should be documented
  2. PyEDS should raise an exception when this occurs
  3. PyEDS should have unit-tests for this use-case

Transitions are allowed on on_init and on user event handlers (as you already use this). The on_init is executed when the state machine reaches its destination state. This is meaningful only on HSM while on FSM every transition goes through only one state, so it is always executed after on_entry.

In the next few days I'll take care of these issues.

dclementson commented 3 years ago

HI Nenad:

Thanks for the update. Take care,

DC

On Tue, Dec 22, 2020 at 5:27 AM Nenad Radulović notifications@github.com wrote:

Hello DC,

Event less transitions are not allowed on PyEDS. That means that on_entry and on_exit does not support taking a transition. This brings up two things:

  1. This behavior should be documented
  2. PyEDS should raise an exception when this occurs
  3. PyEDS should have unit-tests for this use-case

Transitions are allowed on on_init and on user event handlers (as you already use this). The on_init is executed when the state machine reaches its destination state. This is meaningful only on HSM while on FSM every transition goes through only one state, so it is always executed after on_entry.

In the next few days I'll take care of these issues.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nradulovic/pyeds/issues/17#issuecomment-749539645, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGL6X6IJHERLU2VSCVHKJ2TSWCNFRANCNFSM4VAPXNAA .