python模拟进程

代码:

from transitions import Machine

#定义一个我总自己的属性
class xqc(object):
    pass

#创建我自己的一个对象
model = xqc()
#对于状态的些定义
states = ['New', 'Ready', 'Waiting', 'Running', 'Terminated']
#定义状态转移
transitions = [
    {'trigger': 'Admitted', 'source': 'New', 'dest': 'Ready'},
    {'trigger': 'Input', 'source': 'Waiting', 'dest': 'Ready'},
    {'trigger': 'Output', 'source': 'Waiting', 'dest': 'Ready'},
    {'trigger': 'event_completion', 'source': 'Waiting', 'dest': 'Ready'},
    {'trigger': 'event_wait', 'source': 'Running', 'dest': 'Waiting'},
    {'trigger': 'Input', 'source': 'Running', 'dest': 'Waiting'},
    {'trigger': 'Output', 'source': 'Running', 'dest': 'Waiting'},
    {'trigger': 'Interrupt', 'source': 'Running', 'dest': 'Ready'},
    {'trigger': 'Dispatch', 'source': 'Ready', 'dest': 'Running'},
    {'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.event_wait()
print(model.state)
model.Output()
print(model.state)
model.Dispatch()
print(model.state)
model.Exit()
print(model.state)
posted @ 2021-11-28 11:28  20211428谷丰宇  阅读(34)  评论(0编辑  收藏  举报