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

    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

    2运行截图

  • 相关阅读:
    SEO优化范列20120215
    IIS中的上传目录权限设置问题
    c# webservice接口 输出xml
    360浏览器用window.open的话,session会丢失
    iis网站安全设置
    SEO优化20120215
    IIS6.0安全设置方法 .
    优化20120215
    WIN2003的安全设置
    webservice 生成dll的方法
  • 原文地址:https://www.cnblogs.com/wxl2761407387/p/14127495.html
Copyright © 2011-2022 走看看