python模拟进程状态
1 from transitions import Machine 2 # 定义一个自己的类 3 class Matter(object): 4 pass 5 model = Matter() 6 states = ['New', 'Ready', 'Waiting', 'Running','Terminated'] 7 # The trigger argument defines the name of the new triggering method 8 transitions = [ 9 {'trigger': 'Admitted', 'source': 'New', 'dest': 'Ready'}, 10 {'trigger': 'Dispatch', 'source': 'Ready', 'dest': 'Running'}, 11 {'trigger': 'Input/Output or event wait', 'source': 'Running', 'dest': 'Waiting'}, 12 {'trigger': 'Input/Output or event completion', 'source': 'Waiting', 'dest': 'Ready'}, 13 {'trigger':'Exit','source':'Running','dest':'Terminated'}, 14 {'trigger':'Interrupt','source':'Running','dest':'Ready'}] 15 # 初始化 16 machine = Machine(model=model, states=states,transitions=transitions, initial='New') 17 # Test 18 print(model.state) 19 model.Admitted() 20 print(model.state)