zoukankan      html  css  js  c++  java
  • 模拟进程

    1:源代码
    from transitions import Machine

    定义一个自己的类
    class Matter(object):
    pass
    model = Matter()

    状态定义
    states=['New','Ready','Waiting','Running','Terminated']

    定义状态转移
    The trigger argument defines the name of the new triggering method
    transitions = [
    {'trigger': 'Admitted', 'source': 'New', 'dest': 'Ready'},
    {'trigger': 'Input', 'source': 'Waiting', 'dest': 'Ready'},
    {'trigger': 'Output', 'source': 'Waiting', 'dest': 'Ready'},
    {'trigger': 'eventcompletion', 'source': 'Waiting', 'dest': 'Ready'},
    {'trigger': 'eventwait', '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')

    Test
    model.state # solid

    状体转变
    print(model.state)
    model.Admitted()
    print(model.state)
    model.Dispatch()
    print(model.state)
    model.Input()
    print(model.state)
    model.Input()
    print(model.state)
    model.Dispatch()
    print(model.state)
    model.Interrupt()
    print(model.state)
    model.Dispatch()
    print(model.state)
    model.Exit()
    print(model.state

  • 相关阅读:
    .NET 4.5 Task异步编程学习资料
    ASP.NET MVC5 支持PUT 和DELETE
    Web Api
    jexus linux x64[标准版]
    redis-window 集群配置
    响应式网格视图css
    json字符串到js对象的转换
    Activity中UI框架基本概念
    Spring AOP 详解
    行为触发之Android自动化测试instrumentation(一)
  • 原文地址:https://www.cnblogs.com/daijun123/p/14129269.html
Copyright © 2011-2022 走看看