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
I created a very simple test case to reproduce the problem I'm seeing with a more complex workflow. Basically, when I nest chains inside of other chains, then it only processes the first nested chain and never goes on to the next ones.
I'm also seeing another possibly related issue where a chain executes nested elements out of order. Would you expect that to be related to the same issue or should I file a separate issue?
If you want to execute large number of tasks in order, you should refactor your workflow to use a Map instead of a chain. I ran into this same problem, and your best bet is to stay clear of chains.
@chrisw1229@w- Simple explanation for this is that 'group' is a task itself, which operation is to send the task messages. It's implemented similar to this:
@task
def group(tasks):
with app.producer_or_acquire() as producer:
for signature in tasks:
signature.apply_async(publisher=producer)
So in the case of:
chain(group1, group2, task3.si())
group2 will execute after the tasks in the group1 group has been applied,
not when the tasks in that group complete.
In any case you cannot synchronize on a group, that's what chords are for!
And I totally forgot that chained groups are automatically upgraded to a chord. So disregard the last reply (the details of group is still true though, just that chain() will rewrite them to be a chord)
Yes, thanks ask. During my experiments I could see from the worker output that certain combinations were creating chords under the covers, which is why I thought there could be a bug here. I was able to get my example working by converting everything to chords manually. I haven't gotten to try this example on the most recent version of Celery to see if the problem persists, but I should have time to look into this again soon. It's not a huge deal if the answer is just to use chords, but I find the chain/group APIs more clear to understand.
@ask I finally got around to trying this again under Celery 3.0.17 and it looks like there are still bugs. The following snippet still never runs task2 after task1 completes. I also tried adding extra task1 and task2 subtasks to each of the chains and that didn't help.
I also re-tested the nested groups issue I mentioned in an earlier comment and that still runs the tasks out of order too. Celery is definitely upgrading the nested groups to use 2 chords, but for some reason it doesn't behave the same as when I implement it explicitly myself. So this code does not work as expected:
I understand the workflow nesting can get complicated to implement, but I think if we can work out these types of issues Celery provides the most power/flexibility along with the simplest API compared to anything else I've seen.
Activity
AnonymousHelper commentedon Dec 11, 2012
Chains can now chain other chains and use partial arguments (Issue #1057).
Upgrade to celery 3.0.13
chrisw1229 commentedon Dec 11, 2012
Okay thanks.
chrisw1229 commentedon Dec 11, 2012
I'm also seeing another possibly related issue where a chain executes nested elements out of order. Would you expect that to be related to the same issue or should I file a separate issue?
In that example, task 3 executes between some of the task 2 instances, which is not what I would expect.
w- commentedon Feb 27, 2013
i am seeing this too. any comment on this?
AnonymousHelper commentedon Mar 1, 2013
If you want to execute large number of tasks in order, you should refactor your workflow to use a Map instead of a chain. I ran into this same problem, and your best bet is to stay clear of chains.
ask commentedon Mar 4, 2013
@chrisw1229 @w- Simple explanation for this is that 'group' is a task itself, which operation is to send the task messages. It's implemented similar to this:
So in the case of:
group2 will execute after the tasks in the group1 group has been applied,
not when the tasks in that group complete.
In any case you cannot synchronize on a group, that's what chords are for!
ask commentedon Mar 4, 2013
And I totally forgot that chained groups are automatically upgraded to a chord. So disregard the last reply (the details of group is still true though, just that chain() will rewrite them to be a chord)
chrisw1229 commentedon Mar 4, 2013
Yes, thanks ask. During my experiments I could see from the worker output that certain combinations were creating chords under the covers, which is why I thought there could be a bug here. I was able to get my example working by converting everything to chords manually. I haven't gotten to try this example on the most recent version of Celery to see if the problem persists, but I should have time to look into this again soon. It's not a huge deal if the answer is just to use chords, but I find the chain/group APIs more clear to understand.
chrisw1229 commentedon Apr 5, 2013
@ask I finally got around to trying this again under Celery 3.0.17 and it looks like there are still bugs. The following snippet still never runs task2 after task1 completes. I also tried adding extra task1 and task2 subtasks to each of the chains and that didn't help.
I also re-tested the nested groups issue I mentioned in an earlier comment and that still runs the tasks out of order too. Celery is definitely upgrading the nested groups to use 2 chords, but for some reason it doesn't behave the same as when I implement it explicitly myself. So this code does not work as expected:
Re-writing it like this does work correctly though. It's just not quite as readable in my opinion.
I understand the workflow nesting can get complicated to implement, but I think if we can work out these types of issues Celery provides the most power/flexibility along with the simplest API compared to anything else I've seen.
w- commentedon Apr 9, 2013
in case this helps you, a cleaner way of being explicit is detailed here:
#1214 (comment)
ask commentedon Oct 7, 2013
@chrisw1229 The first chain example you had problems with works now in 3.1rc