Is there something wrong with my Python code? (functions)
from celery.decorators import task

def add(x, y):
    add.delay(1, 9)
    return x + y

>>> import tasks
>>> res = tasks.add.delay(5, 2)
>>> res.result()

If I run this code, I expect tasks to be continously added to the queue. But it's not! Only the first task (5,2) gets added to the queue and processed.

There should continuously be tasks being added, due to this line: "add.delay(1,9)"

Note: I need each task to execute another task.


As far as I can see, a periodic_task decorator is creating preiodic tasks, task creates just one task. And delay just executes it asynchronically.

You should just use periodic_task, instead of recursion.

add inside function body refers to original function, not its decorated version.

If you just need to run task repeatedly, use @periodic_task instead. You only need recursion if delay is different each time. In this case, subclass Task instead of using decorator and you'll be able to use recursion without a problem.

You should look at subtasks and callbacks, might give you the answer you are looking for

Need Your Help

How to read a file, pick up data and calculate

c fgets atof

I am reading a book and I can't figure out this try it out : (it is in a non-english language so I translated it)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.