def test_live_spys(fabric_fixture): tazor = ActiveObject() tazor.live_spy = True tazor.live_trace = True tazor.start_at(arming) time.sleep(0.1) tazor.post_fifo(Event(signal=signals.READY)) time.sleep(0.1)
def test_live_spys(): tazor = ActiveObject() tazor.live_spy = True tazor.live_trace = True tazor.start_at(arming) time.sleep(0.1) tazor.post_fifo(Event(signal=signals.READY)) time.sleep(0.1)
print("exiting outer_state") status = return_status.HANDLED else: chart.temp.fun = chart.top status = return_status.SUPER return status @spy_on def inner_state(chart, e): status = return_status.UNHANDLED if (e.signal == signals.ENTRY_SIGNAL): print("hello from inner_state") status = return_status.HANDLED elif (e.signal == signals.EXIT_SIGNAL): print("exiting inner_state") status = return_status.HANDLED else: chart.temp.fun = outer_state status = return_status.SUPER return status if __name__ == '__main__': ao = ActiveObject("ao") ao.live_trace = True ao.start_at(outer_state) ao.post_fifo(Event(signal=signals.Reset)) # let the thread catch up before we exit main time.sleep(0.01)
status = return_status.UNHANDLED # the event processor is asking us about events called INIT_SIGNAL if (e.signal == signals.INIT_SIGNAL): # we are transitioning to inner_state # we let the trans method, set temp.fun and our return status status = chart.trans(inner_state) # we do this for any other event else: chart.temp.fun = chart.top status = return_status.SUPER return status @spy_on # enables the live trace def inner_state(chart, e): # we do this for all events chart.temp.fun = outer_state status = return_status.SUPER return status if __name__ == '__main__': ao = ActiveObject('ao') ao.live_trace = True # so we can see what is happening # Create a thread and start our state machine ao.start_at(outer_state) # Run our main program so that the state machine's thread # can do some stuff. # The state machine's thread will be stopped when our main thread stops time.sleep(0.01)
@spy_on def inner_state(chart, e): status = return_status.UNHANDLED if (e.signal == signals.ENTRY_SIGNAL): print("{}: hello from inner_state".format(chart.name)) status = return_status.HANDLED elif (e.signal == signals.EXIT_SIGNAL): print("{}: exiting inner_state".format(chart.name)) status = return_status.HANDLED else: chart.temp.fun = outer_state status = return_status.SUPER return status if __name__ == '__main__': ao1 = ActiveObject("ao1") ao1.live_trace = True ao1.start_at(outer_state) ao1.post_fifo(Event(signal=signals.Hook)) ao1.post_fifo(Event(signal=signals.Reset)) ao2 = ActiveObject("ao2") ao2.live_trace = True ao2.start_at(inner_state) ao2.post_fifo(Event(signal=signals.Hook)) ao2.post_fifo(Event(signal=signals.Reset)) # let the thread catch up before we exit main time.sleep(0.01)