Beispiel #1
0
 def __init__(self, broker, workers=1, thread_factory=Thread):
     self.broker = broker
     self.workers = workers
     self.thread_factory = thread_factory
     self.threads = []
     self.stop_event = Event()
     ts = TaskSpace(__name__)
     ts.task(lambda: None, 'noop')
     broker.expose(ts, replace=True)
Beispiel #2
0
 def __init__(self, broker, workers=1, thread_factory=Thread):
     self.broker = broker
     self.workers = workers
     self.thread_factory = thread_factory
     self.threads = []
     self.stop_event = Event()
     ts = TaskSpace(__name__)
     ts.task(lambda:None, 'noop')
     broker.expose(ts, replace=True)
Beispiel #3
0
    def expose(self, obj, replace=False):
        """Expose a TaskSpace or task callable.

        :param obj: A TaskSpace or task callable.
        :param replace: Replace existing task if True. Otherwise (by default),
            raise ValueError if this would replace an existing task.
        """
        if isinstance(obj, TaskSpace):
            space = obj
        else:
            space = TaskSpace()
            space.task(obj)
        for name, func in space.tasks.items():
            if name in self.tasks and not replace:
                raise ValueError('task %r conflicts with existing task' % name)
            self.tasks[name] = func
Beispiel #4
0
    def expose(self, obj, replace=False):
        """Expose a TaskSpace or task callable.

        :param obj: A TaskSpace or task callable.
        :param replace: Replace existing task if True. Otherwise (by default),
            raise ValueError if this would replace an existing task.
        """
        if isinstance(obj, TaskSpace):
            space = obj
        else:
            space = TaskSpace()
            space.task(obj)
        for name, func in space.tasks.items():
            if name in self.tasks and not replace:
                raise ValueError('task %r conflicts with existing task' % name)
            self.tasks[name] = func