逸致

导航

python模拟进程状态

代码内容

class Matter(object):
    pass
model=Matter
states=['New','Ready','Waiting','Running','Terminated']
transitions=[
    {'trigger':'Admitted','source':'New','dest': 'Ready' },
    {'trigger':'Dispatch','source':'Ready','dest': 'Running'},
    {'trigger':'Interrupt','source':'Running','dest': 'Ready'},
    {'trigger':'Input or event completion','source':'Waiting','dest': 'Ready'},
    {'trigger':'Output or event completion','source':'Waiting','dest': 'Ready'},
    {'trigger':'Input or event wait','source':'Running','dest': 'Waiting'},
    {'trigger':'Output or event wait','source':'Running','dest': 'Waiting'},
    {'trigger':'Exit','source':'Running','dest': 'Terminated'}]
machine = Machine(model=model, states=states, transitions=transitions, initial='New')
print(model.state)
model.Admitted()
print(model.state)
model.Dispatch()
print(model.state)
model.Exit()
print(model.state)

代码运行结果截图:

posted on 2021-11-28 14:24  逸致  阅读(21)  评论(0编辑  收藏  举报