python状态机库
easystate的Python项目详细描述
python的简易状态机
从easystate导入* 导入时间 速度=1
- 开始上课(状态):
- 排放定义(自):
- 打印“开始” 时间。睡眠(速度)
- 启动时的定义(自,E):
- 打印“你好”
- def on_finish(self,e):
- 自我过渡(“倾听”)
课堂听力(状态):
- def eval(self):
- print ‘Listening’ time.sleep(SPEED) self.raiseEvent(“connect”)
- def on_start(self,e):
- print “Preparing for listening”
- def on_connect(self,e):
- self.transition(‘Negotiation’)
- 类协商(状态):
- 排放定义(自):
- 打印“检查有效性” 睡眠时间(速度) 打印“身份验证” 睡眠时间(速度) 打印“注册” self.transition(“连接的”)
- 启动时的定义(自,E):
- 打印“协商”
- 类连接(状态):
- 排放定义(自):
- 打印“已连接”
- def on_finish(self,e):
- 自我过渡(“倾听”)
m=状态机(initialState=“starting”) m.appendState(启动()) m.appendState(侦听()) m.appendState(协商()) m.appendState(connected()) m.start()