How can I call a worker from a worker? This seems to be a simple representation of the puzzle I'm trying to solve:
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()
Here's the error output:
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'
It also doesn't terminate because it failed before the stop()
call.