python模拟进程状态
2021-03-11 09:29
标签:input 自己的 att get run 初始 stat event trigger 参考:http://www.cnblogs.com/21207-iHome/p/6085334.html 代码:from transitions import Machine class Matter(object): model = Matter() states = [‘New‘, ‘Ready‘, ‘Waiting‘, ‘Running‘, ‘Terminated‘] transitions = [ machine = Machine(model=model, states=states, print(model.state) # New model.Admitted() model.Dispatch() model.InputOutputoreventwait() model.InputOutputoreventcompletion() model.Dispatch() model.Interrupt() model.Dispatch() model.Exit() python模拟进程状态 标签:input 自己的 att get run 初始 stat event trigger 原文地址:https://www.cnblogs.com/jiangcun/p/14128832.html定义一个自己的类
pass状态定义
定义状态转移
{‘trigger‘: ‘Admitted‘, ‘source‘: ‘New‘, ‘dest‘: ‘Ready‘},
{‘trigger‘: ‘Dispatch‘, ‘source‘: ‘Ready‘, ‘dest‘: ‘Running‘},
{‘trigger‘: ‘Interrupt‘, ‘source‘: ‘Running‘, ‘dest‘: ‘Ready‘},
{‘trigger‘: ‘InputOutputoreventwait‘, ‘source‘: ‘Running‘, ‘dest‘: ‘Waiting‘},
{‘trigger‘: ‘InputOutputoreventcompletion‘,
‘source‘: ‘Waiting‘, ‘dest‘: ‘Ready‘},
{‘trigger‘: ‘Exit‘, ‘source‘: ‘Running‘, ‘dest‘: ‘Terminated‘}]初始化
transitions=transitions, initial=‘New‘)Test
状体转变
print(model.state) # Ready
print(model.state) # Running
print(model.state) # Waiting
print(model.state) # Ready
print(model.state) # Running
print(model.state) # Ready
print(model.state) # Running
print(model.state) # Terminated
上一篇:数组方法之concat
下一篇:Spring中的Aware接口