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


Python Task._add_child方法代码示例

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


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

示例1: Workflow

# 需要导入模块: from Task import Task [as 别名]
# 或者: from Task.Task import _add_child [as 别名]
class Workflow(object):
    """
    The engine that executes a workflow.
    It is a essentially a facility for managing all branches.
    A Workflow is also the place that holds the attributes of a running workflow.
    """

    def __init__(self, workflow_spec, deserializing=False, **kwargs):
        """
        Constructor.

        :param deserializing: set to true when deserializing to avoid
        generating tasks twice (and associated problems with multiple
        hierarchies of tasks)
        """
        assert workflow_spec is not None
        LOG.debug("__init__ Workflow instance: %s" % self.__str__())
        self.spec = workflow_spec
        self.task_id_assigner = TaskIdAssigner()
        self.attributes = {}
        self.outer_workflow = kwargs.get('parent', self)
        self.locks = {}
        self.last_task = None
        if deserializing:
            assert 'Root' in workflow_spec.task_specs
            root = workflow_spec.task_specs['Root']  # Probably deserialized
        else:
            if 'Root' in workflow_spec.task_specs:
                root = workflow_spec.task_specs['Root']
            else:
                root = specs.Simple(workflow_spec, 'Root')
        self.task_tree = Task(self, root)
        self.success = True
        self.debug = False

        # Events.
        self.completed_event = Event()

        # Prevent the root task from being executed.
        self.task_tree.state = Task.COMPLETED
        start = self.task_tree._add_child(self.spec.start, state=Task.FUTURE)

        self.spec.start._predict(start)
        if 'parent' not in kwargs:
            start.task_spec._update_state(start)
        #start.dump()

    def is_completed(self):
        """
        Returns True if the entire Workflow is completed, False otherwise.
        """
        mask = Task.NOT_FINISHED_MASK
        iter = Task.Iterator(self.task_tree, mask)
        try:
            iter.next()
        except:
            # No waiting tasks found.
            return True
        return False

    def _get_waiting_tasks(self):
        waiting = Task.Iterator(self.task_tree, Task.WAITING)
        return [w for w in waiting]

    def _task_completed_notify(self, task):
        if task.get_name() == 'End':
            self.attributes.update(task.get_attributes())
        # Update the state of every WAITING task.
        for thetask in self._get_waiting_tasks():
            thetask.task_spec._update_state(thetask)
        if self.completed_event.n_subscribers() == 0:
            # Since is_completed() is expensive it makes sense to bail
            # out if calling it is not necessary.
            return
        if self.is_completed():
            self.completed_event(self)

    def _get_mutex(self, name):
        if name not in self.locks:
            self.locks[name] = mutex()
        return self.locks[name]

    def get_attribute(self, name, default=None):
        """
        Returns the value of the attribute with the given name, or the given
        default value if the attribute does not exist.

        :type  name: string
        :param name: An attribute name.
        :type  default: obj
        :param default: Return this value if the attribute does not exist.
        :rtype:  obj
        :returns: The value of the attribute.
        """
        return self.attributes.get(name, default)

    def cancel(self, success=False):
        """
        Cancels all open tasks in the workflow.

#.........这里部分代码省略.........
开发者ID:dave42,项目名称:SpiffWorkflow,代码行数:103,代码来源:Workflow.py

示例2: Job

# 需要导入模块: from Task import Task [as 别名]
# 或者: from Task.Task import _add_child [as 别名]
class Job(Trackable):
    """
    The engine that executes a workflow.
    It is a essentially a facility for managing all branches.
    A Job is also the place that holds the attributes of a running workflow.
    """

    def __init__(self, workflow, **kwargs):
        """
        Constructor.
        """
        Trackable.__init__(self)
        assert workflow is not None
        self.workflow        = workflow
        self.attributes      = {}
        self.outer_job       = kwargs.get('parent', self)
        self.locks           = {}
        self.last_node       = None
        self.task_tree       = Task(self, Tasks.Simple(workflow, 'Root'))
        self.success         = True
        self.debug           = False

        # Prevent the root node from being executed.
        self.task_tree.state = Task.COMPLETED
        start                = self.task_tree._add_child(workflow.start)

        workflow.start._predict(start)
        if not kwargs.has_key('parent'):
            start.spec._update_state(start)
        #start.dump()


    def is_completed(self):
        """
        Returns True if the entire Job is completed, False otherwise.
        """
        mask = Task.NOT_FINISHED_MASK
        iter = Task.Iterator(self.task_tree, mask)
        try:
            next = iter.next()
        except:
            # No waiting nodes found.
            return True
        return False


    def _get_waiting_tasks(self):
        waiting = Task.Iterator(self.task_tree, Task.WAITING)
        return [w for w in waiting]


    def _task_completed_notify(self, task):
        if task.get_name() == 'End':
            self.attributes.update(task.get_attributes())
        # Update the state of every WAITING node.
        for node in self._get_waiting_tasks():
            node.spec._update_state(node)
        if self.signal_subscribers('completed') == 0:
            # Since is_completed() is expensive it makes sense to bail
            # out if calling it is not necessary.
            return
        if self.is_completed():
            self.signal_emit('completed', self)


    def _get_mutex(self, name):
        if not self.locks.has_key(name):
            self.locks[name] = mutex()
        return self.locks[name]


    def get_attribute(self, name, default = None):
        """
        Returns the value of the attribute with the given name, or the given
        default value if the attribute does not exist.

        @type  name: string
        @param name: An attribute name.
        @type  default: obj
        @param default: Return this value if the attribute does not exist.
        @rtype:  obj
        @return: The value of the attribute.
        """
        return self.attributes.get(name, default)


    def cancel(self, success = False):
        """
        Cancels all open tasks in the job.

        @type  success: boolean
        @param success: Whether the Job should be marked as successfully
                        completed.
        """
        self.success = success
        cancel       = []
        mask         = Task.NOT_FINISHED_MASK
        for node in Task.Iterator(self.task_tree, mask):
            cancel.append(node)
        for node in cancel:
#.........这里部分代码省略.........
开发者ID:gonicus,项目名称:clacks,代码行数:103,代码来源:Job.py


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