1

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.

  • 1
    Osso and I came up with this event-based solution: http://pastebin.com/xHKuPzDq – Jim Scarborough Aug 19 '16 at 00:29
  • 1
    Replacing `yield` with `yield from` at least shows the events firing for subsequent calls, but it does not show the results coming back. I suspect the answer is related to this: http://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do-in-python/31042491#31042491 , but I have not gotten to the bottom of it yet. – Jim Scarborough Aug 19 '16 at 01:54
  • Sorry I've been super busy with work, etc... Ill take a look into this more closely soon! – James Mills Aug 25 '16 at 03:26
  • This [patch](https://gist.github.com/prologic/ed709a76db4f1d23e14c8311ea4d20a3) solves some of the problem; but needs further looking in to as it gets [stuck](https://gist.github.com/af85b0d7a860352f157dcbd1b2dee57f) – James Mills Aug 25 '16 at 04:17

0 Answers0