我怎样才能让工人折返?

时间:2016-08-18 01:38:48

标签: python circuits-framework

如何从工人那里打电话给工人?这似乎是我试图解决的难题的简单表示:

import time
from circuits import BaseComponent, Worker, Debugger, task, handler

class App(BaseComponent):
    def factorial(self, n):
        time.sleep(1)
        if n > 1:
            nn = yield self.call(task(self.factorial, n-1))
            return n * nn.value
        else:
            return 1

    @handler("started")
    def started(self, *args):
        Worker().register(self)
        rv = yield self.call(task(self.factorial, 5))
        print(rv.value)
        self.stop()

(App() + Debugger()).run()

这里是错误输出:

ERROR  (<task[*] (<bound method App.factorial of <App/* 26821:MainThread (queued=1) [R]>>, 5 )>) (<class 'AttributeError'>): AttributeError("'generator' object has no attribute 'task_event'",)
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/circuits/core/manager.py", line 841, in processTask
    task_state.task_event = event
AttributeError: 'generator' object has no attribute 'task_event'

它也没有终止,因为它在stop()调用之前失败了。

0 个答案:

没有答案