You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be better illustrated as sub_A = A.s(<some specific input>). If the outcome of A is deterministic based on a particular input, we could share the result of one execution. However, as you said, sub_A is called twice.
Doing this
sub_A.options.setdefault('task_id', uuid())
before we get() seems to work, but it would be nice if there was a more supported way of doing this.
I should add: I would expect the subtask to be called twice in the original snippit that I posted.
The requested functionality would require some new way of denoting a subtask which could appear multiple times in a dependency graph, where we should share the single-execution result.
This is much more straightforward for immutable subtasks. It seems things might get pretty tricky if the subtask was mutable.
What you're asking is caching:
Have a task given a determinate task_id, which allows us not to execute it if the result is already here, or if it is already executing.
But this is complicated for several reasons:
How to determine if the task is already running? We can interrogate the other workers, but this will lead to a race condition (if the worker starts executing A right after we ask for it, and we start it again anyway).
Some backends (AMQP) won't be able to support caching, ever.
I don't think you need to check if it's already running, just need some way to refer to a task that has already been called, e.g.:
result = add.s(2, 2).delay()
chord(result, add.s(8, 8)(xsum.s())
This does not currently work, but you can imagine chord could skip sending a message if it encounters an AsyncResult instance and just use the id as-is.
On top of that we would need a way to refer to the result of a subtask to combine it in expressions,
as in the original example, this way the subtask is only called once and subsequent calls will return the same result instance, e.g:
And does the dependencies will be respected? In this A, B and C in parallel and only launch D when A and B are successful and E only when A and C are successful.
I just ran into this issue myself. Really putting a damper on my excitement to use celery.
I was wondering if anybody knows a good workaround (without multiple blocking stages)?
Basically we need a "reverse chord", where instead of the results of a group of tasks feeding into a single task, we have the result of a single task feeding into a group of many tasks.
celery.reverse_chord(add.s(1, 2), [sub.s(3), sub.s(4), sub.s(5)])
# sum = 1 + 2# result = [sum - 3, sum - 4, sum - 5]
I just ran into this issue myself. Really putting a damper on my excitement to use celery.
I was wondering if anybody knows a good workaround (without multiple blocking stages)?
Basically we need a "reverse chord", where instead of the results of a group of tasks feeding into a single task, we have the result of a single task feeding into a group of many tasks.
celery.reverse_chord(add.s(1, 2), [sub.s(3), sub.s(4), sub.s(5)])
sum = 1 + 2
result = [sum - 3, sum - 4, sum - 5]
With some abuse of the task message format, this can be achieved by basically making header tasks members of multiple “bodies” and patching on_chord_part_return (for the backends that use it) basically to just loop over them:
In there I am more or less stuffing whatever I feel like in request.chord, so one may hesitate to run it in production, and we also use something slightly different. But in essence nothing more than making “group,” “group_index,” and “chord” into plural versions of themselves in the message format would suffice.
I’m not 100% sure but I think the main blockers here could be easily overcome:
I think the task/request message format would need to be extended (could be backwards-compatible) to support the plural forms of the above mentioned entities
I’m a bit lost with the cloud of related open issues here, as there seem to be some abstract or elegant things like “reusable signatures” and whatnot being requested, when in fact maybe people just want pure DAG workflow support in Celery and it would be better to just deliver that, rather than finding some way to merge the concept of a DAG with Celery’s more historical/strict notions.
Having proved the ease of DAG support with trivial monkey patches and fairly straightforward extensions to the message format, do you see some path to integrating something like this without ballooning the scope? I see it as huge potential for added value to get DAG support in Celery as a lot of people seem to want it; many seem be led to believe by the docs that Celery has it (perhaps simply because of the use of the term “workflows” on this page and the many graph references), and then have to painfully learn it does not.
Activity
ask commentedon Jul 30, 2012
A subtask instance may be called multiple times, e.g:
In addition chord, group, chain etc may clone the tasks, this to set new task_ids etc without affecting
later calls.
ask commentedon Jul 30, 2012
oh and my point, which is that
sub_Ais called twice in your example.davemt commentedon Jul 31, 2012
Yes, and this is not always desired.
It would be better illustrated as
sub_A = A.s(<some specific input>). If the outcome of A is deterministic based on a particular input, we could share the result of one execution. However, as you said,sub_Ais called twice.Doing this
before we
get()seems to work, but it would be nice if there was a more supported way of doing this.davemt commentedon Aug 1, 2012
I should add: I would expect the subtask to be called twice in the original snippit that I posted.
The requested functionality would require some new way of denoting a subtask which could appear multiple times in a dependency graph, where we should share the single-execution result.
This is much more straightforward for
immutablesubtasks. It seems things might get pretty tricky if the subtask was mutable.steeve commentedon Aug 28, 2012
What you're asking is caching:
Have a task given a determinate
task_id, which allows us not to execute it if the result is already here, or if it is already executing.But this is complicated for several reasons:
ask commentedon Mar 5, 2013
I don't think you need to check if it's already running, just need some way to refer to a task that has already been called, e.g.:
This does not currently work, but you can imagine
chordcould skip sending a message if it encounters anAsyncResultinstance and just use the id as-is.On top of that we would need a way to refer to the result of a subtask to combine it in expressions,
as in the original example, this way the subtask is only called once and subsequent calls will return the same result instance, e.g:
afarbos commentedon Dec 5, 2015
I am not sure to get it. Does res_A will be executed twice in this case or not?
And does the dependencies will be respected? In this A, B and C in parallel and only launch D when A and B are successful and E only when A and C are successful.
ask commentedon Dec 9, 2015
Yes!
neoascetic commentedon Mar 10, 2016
Want this :)
GlennS commentedon Jun 22, 2016
Just a note that this appears to be the same issue as discussed here.
I wasn't able to figure out how to pass a list of task_ids to the underlying chord implementation.
ask commentedon Jun 23, 2016
Closing this, as with current resources it will take 10 years to complete.
7 remaining items
auvipy commentedon Mar 19, 2021
I think we should move this to next milestone
thedrow commentedon Mar 21, 2021
I agree. This can be done only with an event loop as we have to check the backend first for a result which means waiting.
This requires an event loop.
In addition, it requires the task to be declared as idempotent which is something we currently don't support.
jpsnyder commentedon Mar 23, 2023
I just ran into this issue myself. Really putting a damper on my excitement to use celery.
I was wondering if anybody knows a good workaround (without multiple blocking stages)?
Basically we need a "reverse chord", where instead of the results of a group of tasks feeding into a single task, we have the result of a single task feeding into a group of many tasks.
sjkoelle commentedon Dec 6, 2023
Has there been any progress? Support for arbitrary DAGs would be fantastic.
PythonFZ commentedon Oct 26, 2024
Is this still on the Roadmap? I do have my project workflow as
networkxgraph and I am trying to run it using celery phasing exactly this issue.simonepozzoli-pix4d commentedon May 24, 2025
Isn't it possible to use?
auvipy commentedon May 27, 2025
we need contributions here.
chrisbarber commentedon Nov 3, 2026
With some abuse of the task message format, this can be achieved by basically making header tasks members of multiple “bodies” and patching
on_chord_part_return(for the backends that use it) basically to just loop over them:Here’s a gist with some examples building up in complexity from two overlapping chords towards a general DAG: https://gist.github.com/chrisbarber/066d507b454de1dffb71a37e39d3c385
Here’s a ~200 LOC DAG canvas-compatible element modelled after something we’ve been running in production for a year, also with proof-of-concept on that repo for how easy it is to make work with the non key-value (polling) backends: https://github.com/Carrot-Consortium/celery-dag
In there I am more or less stuffing whatever I feel like in
request.chord, so one may hesitate to run it in production, and we also use something slightly different. But in essence nothing more than making “group,” “group_index,” and “chord” into plural versions of themselves in the message format would suffice.I’m not 100% sure but I think the main blockers here could be easily overcome:
Having proved the ease of DAG support with trivial monkey patches and fairly straightforward extensions to the message format, do you see some path to integrating something like this without ballooning the scope? I see it as huge potential for added value to get DAG support in Celery as a lot of people seem to want it; many seem be led to believe by the docs that Celery has it (perhaps simply because of the use of the term “workflows” on this page and the many graph references), and then have to painfully learn it does not.
auvipy commentedon Nov 4, 2026
I saw the code of your celery dag, I think that can be tried in celery core