当前位置: 首页>>代码示例>>Python>>正文


Python Machine.is_shutdown方法代码示例

本文整理汇总了Python中transitions.Machine.is_shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python Machine.is_shutdown方法的具体用法?Python Machine.is_shutdown怎么用?Python Machine.is_shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transitions.Machine的用法示例。


在下文中一共展示了Machine.is_shutdown方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from transitions import Machine [as 别名]
# 或者: from transitions.Machine import is_shutdown [as 别名]
class GraphEngine:
    states = ['new', 'resolved', 'unresolved', 'running', 'idle', 'stopping', 'stopped', 'shutdown']
    transitions = [
        {'trigger': 'resolve', 'source': 'new', 'dest': 'resolved'},
        {'trigger': 'resolve', 'source': 'unresolved', 'dest': 'resolved'},
        {'trigger': 'unresolve', 'source': 'new', 'dest': 'unresolved'},
        {'trigger': 'run', 'source': ['resolved', 'idle'], 'dest': 'running'},
        {'trigger': 'idle', 'source': 'running', 'dest': 'idle'},
        {'trigger': 'stop', 'source': ['running', 'idle'], 'dest': 'stopping'},
        {'trigger': 'stop', 'source': 'stopping', 'dest': 'stopped'},
        {'trigger': 'shutdown', 'source': 'stopped', 'dest': 'shutdown'},
    ]

    def __init__(self, graph=None, loop=None):
        self.logger = logging.getLogger(__name__)
        self.state = Machine(states=GraphEngine.states, transitions=GraphEngine.transitions, initial='new')
        if loop:
            self._loop = loop
        else:
            self._loop = asyncio.get_event_loop()
        self.processes = dict()
        self.connections = dict()
        self._graph = None
        self._process_manager = None
        if graph:
            self.bind(graph)

    async def bind(self, g):
        """
        Bind the engine to a graph description and instantiates processes
        :param g:
        :return:
        """
        if not (self.state.is_new() or self.state.is_shutdown()):
            raise EngineException("Engine is already bounded to a graph instance")
        self._graph = g
        await self._init_graph()

    async def init_from_dictionary(self, dict_spec: dict):
        # Allow 'graph' as optional root
        if 'graph' in dict_spec:
            graph_config = dict_spec.get('graph')
        else:
            graph_config = dict_spec

        name = graph_config.get('name', None)
        description = graph_config.get('description', None)
        author = graph_config.get('author', None)
        date = graph_config.get('date', None)
        graph = Graph(name, description, author, date)

        processes = graph_config.get('processes', dict())
        for process in processes:
            component_name = processes[process].get('component', None)
            if not component_name:
                raise GraphException("No component class given for process '%s'", process)
            graph.add_process(process, component_name)

        connections = graph_config.get('connections')
        for cnx in connections:
            try:
                source_component = cnx['source']['process']
                source_port = cnx['source']['port']
                target_component = cnx['target']['process']
                target_port = cnx['target']['port']
                cnx_capacity = cnx.get('capacity', 1) # TODO: don't hard-code, use default
                cnx_name = cnx.get('name', None)
            except KeyError as ke:
                raise GraphException("Invalid parameters for connection '%s' definition" % cnx_name) from ke
            graph.add_connection(cnx_name, source_component, source_port, target_component, target_port, cnx_capacity)

        await self.bind(graph)

    def _get_process(self, process_name, silent=True):
        """
        Get a process by its name. Raises a GraphException if no process is found
        :param self:
        :param process_name:
        :return:
        """
        return [p for p in self.processes.values() if p.name == process_name]

    async def _init_processes(self):
        for proc_desc in self._graph.processes_desc:
            try:
                process = new_component_instance(proc_desc.class_name, proc_desc.process_name)
                self.processes[process.id] = process
                self.logger.debug("Process '%s' created (Id=%s)" % (process.name, process.id))
            except ComponentException as ce:
                raise GraphException("Process '%s' instanciation failed" % process.name) from ce

    async def _init_connections(self):
        for cnx_desc in self._graph.connections_desc:

            # find source : source process output port
            source_port = None
            try:
                process_list = self._get_process(cnx_desc.source_process_name)
                if len(process_list) > 1:
                    raise GraphException("Can't create connection '%s': ambiguous process name '%s'" % (cnx_desc.connection_name, cnx_desc.source_process_name))
#.........这里部分代码省略.........
开发者ID:beerfactory,项目名称:hbflow,代码行数:103,代码来源:engine.py


注:本文中的transitions.Machine.is_shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。