Skip to content

Instantly share code, notes, and snippets.

@fabb
Created February 23, 2013 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabb/5019653 to your computer and use it in GitHub Desktop.
Save fabb/5019653 to your computer and use it in GitHub Desktop.
Issue #4 in PySCXML: transition also exits & enters again unaffected states
import time
from scxml.pyscxml import StateMachine
import logging
logging.basicConfig(level=logging.NOTSET) # show detailed debug info
xml = '''
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0">
<state id="main">
<onentry>
<log expr="'hello main'"/>
</onentry>
<parallel>
<state id="P1">
<onentry>
<log expr="'hello P1'"/>
</onentry>
<transition event="p1x" target="P1f">
<log expr="'transition event p1x'" />
</transition>
<onexit>
<log expr="'bye P1'"/>
</onexit>
<state id="bla1">
<onentry>
<log expr="'hello bla1'"/>
</onentry>
<onexit>
<log expr="'bye bla1'"/>
</onexit>
</state>
<final id="P1f">
<onentry>
<log expr="'hello final P1f'"/>
</onentry>
</final>
</state>
<state id="P2">
<onentry>
<log expr="'hello P2'"/>
</onentry>
<transition event="p2x" target="P2f">
<log expr="'transition event p2x'" />
</transition>
<onexit>
<log expr="'bye P2'"/>
</onexit>
<state id="bla2">
<onentry>
<log expr="'hello bla2'"/>
</onentry>
<onexit>
<log expr="'bye bla2'"/>
</onexit>
</state>
<final id="P2f">
<onentry>
<log expr="'hello final P2f'"/>
</onentry>
</final>
</state>
</parallel>
<transition event="e" target="f">
<log expr="'transition event e'" />
</transition>
<onexit>
<log expr="'bye main'"/>
</onexit>
</state>
<final id="f">
<onentry>
<log expr="'hello final f'"/>
</onentry>
</final>
</scxml>
'''
if __name__ == '__main__':
sm = StateMachine(xml)
sm.start_threaded()
time.sleep(1) #needed, as an immediate send might get ignored, also see issue #3 in PySCXML
sm.send("p1x")
time.sleep(1)
hello main
hello P1
hello bla1
hello P2
hello bla2
INFO:pyscxml.pyscxml_session_43744504.interpreter:external event found: p1x
bye bla2
bye P2
bye bla1
bye P1
transition event p1x
hello P1
hello final P1f
hello P2
hello bla2
INFO:pyscxml.pyscxml_session_43744504.interpreter:new config: {main, main_parall
el_child_3, P1, P1f, P2, bla2}
INFO:pyscxml.pyscxml_session_43744504.interpreter:internal event found: done.sta
te.P1
Inspecting the log, the following things should *not* happen:
7 bye bla2
8 bye P2
10 bye P1
12 hello P1
14 hello P2
15 hello bla2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment