1 Star 0 Fork 0

zhao-shu-bo/czsf

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
python模拟进程状态 1.49 KB
Copy Edit Raw Blame History
zhao-shu-bo authored 2021-11-23 23:14 +08:00 . add python模拟进程状态.
from transitions import Machine
# 定义一个自己的类
class Matter(object):
pass
model = Matter()
# 状态定义
states=['New', 'Ready', 'Running', 'Waiting','Terminated']
# 定义状态转移
# The trigger argument defines the name of the new triggering method
transitions = [
{'trigger': 'Admitted', 'source': 'New', 'dest': 'Ready' },
{'trigger': 'Dispatch', 'source': 'Ready', 'dest': 'Running'},
{'trigger': 'Interrupt', 'source': 'Running', 'dest': 'Ready'},
{'trigger': 'InputOutput', 'source': 'Running', 'dest': 'Waiting'},
{'trigger': 'event_wait', 'source': 'Running', 'dest': 'Waiting'},
{'trigger': 'InputOutput', 'source': 'Waiting','dest':'Ready'},
{'trigger': 'event_completion', 'source': 'Waiting','dest':'Ready'},
{'trigger': 'Exit','source':'Running','dest':'Terminated'}]
# 初始化
machine = Machine(model=model, states=states, transitions=transitions, initial='New')
# Test
print(model.state)# New
# 状体转变
model.Admitted()
print(model.state)# Ready
model.Dispatch()
print(model.state)# Running
model.event_wait()
print(model.state)# Waiting
model.InputOutput()
print(model.state)# Ready
model.Dispatch()
print(model.state)# Running
model.InputOutput()
print(model.state)# Waiting
model.event_completion()
print(model.state)# Ready
model.Dispatch()
print(model.state)# Running
model.Interrupt()
print(model.state)# Ready
model.Dispatch()
print(model.state)# Running
model.Exit()
print(model.state)# Terminated
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhao-shu-bo/czsf.git
git@gitee.com:zhao-shu-bo/czsf.git
zhao-shu-bo
czsf
czsf
master

Search