Created
July 12, 2014 20:18
-
-
Save harlowja/c5d4cf8e9ebf8ee8bdfa to your computer and use it in GitHub Desktop.
fsm-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from taskflow.types import fsm | |
from taskflow import states as st | |
m = fsm.FSM(st.UNDEFINED) | |
def on_enter(new_state, event): | |
print("Entering new state '%s' in " | |
"response to event '%s'" % (new_state, event)) | |
def on_exit(old_state, event): | |
print("Exiting old state '%s' in " | |
"response to event '%s'" % (old_state, event)) | |
m.add_state(st.UNDEFINED) | |
m.add_state(st.RUNNING) | |
m.add_state(st.SUCCESS, terminal=True) | |
m.add_transition(st.UNDEFINED, st.RUNNING, 'start', | |
on_enter=on_enter, on_exit=on_exit) | |
m.add_transition(st.RUNNING, st.SUCCESS, 'done', | |
on_enter=on_enter, on_exit=on_exit) | |
m.add_reaction(st.RUNNING, 'start', lambda old_state, new_state, event: 'done') | |
m.reset() | |
print m.pformat() | |
for s in m.run_iter('start'): | |
print s | |
print m.pformat() | |
print m.pformat() | |
print m.terminated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment