Celery: How to ignore task result in chord or chain?
There is a built-in functionality to ignore result in chaining and others - immutable subtask. You can use .si() shortcut instead of .s() or .subtask(immutable=True)
More details here: http://docs.celeryproject.org/en/master/userguide/canvas.html#immutability
One possible solution has already posted, but I'd like to add further clarification and an alternate solution (and in some cases a superior one).
The error you're seeing, which indicates that your task's signature needs to take into account a second parameter, is due to the fact that when calling tasks in a chain
, Celery automatically pushes each tasks result
as the first parameter of the following task.
From the docs:
Tasks can be linked together, which in practice means adding a callback task:
>>> res = add.apply_async((2, 2), link=mul.s(16))>>> res.get()4
The linked task will be applied with the result of its parent task as the first argument
Therefore, in your case, you could rewrite your task like this:
@celery.taskdef tprint(result, word): print word
If you're not going to do anything with the result, you may as well ignore it, by changing the decorator thus:
@celery.task(ignore_result=True)
And then you won't have to change your task signature.
Sorry, that last point needs further research.
You can try doing something like this.Instead of having a single parameter for function tprint you can have 2 parameters
def tprint(word, x=None): print word
then
chain(tprint.s('a', 0) | tprint.s('b'))()