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
{{ message }}
Repository navigation
group.skew() removes all tasks if group input is generator #4298
I believe this is a bug in celery.utils.functional.regen. Compare the outputs of regen on 4.1.0 (which has this bug) and 3.1.25 (which doesn't):
On Celery 4.1.0:
In [1]: from celery.utils.functional import regen
In [2]: gen = regen(i for i in range(10))
In [3]: [i for i in gen]
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In [4]: [i for i in gen]
Out[4]: []
On Celery 3.1.25:
In [1]: from celery.utils.functional import regen
In [2]: gen = regen(i for i in range(10))
In [3]: [i for i in gen]
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In [4]: [i for i in gen]
Out[4]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In [5]: [i for i in gen]
Out[5]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Looking at 9982773 it would appear that __consumed doesn't get updated inside __iter__.
Doing print(group) first makes things work as expected because __getitem__ is called and populates __consumed correctly. Then subsequent calls to __iter__ work as expected too.
A more proper workaround is to either only pass lists and tuples to group, or if you're using something like Task.chunks, reassign tasks with a list, e.g.:
Finally, #4459 will (probably) fix this issue too. @auvipy would you mind adding tests for this bug into your PR? Or if you prefer, I can open a separate PR that addresses this issue only.
I traced this back to get repro on the originally reported versions as well as current master (420e393). Worth noting that I made the mistake of thinking it was fixed because I was printing the tasks in the group between steps in the MRTC in this issue's summary to see what was going on. Doing so concretises the generator underlying the _regen instance. Here's my new MRTC which needs a backend running for the task submission if the expected behaviour is to be observed:
importceleryapp=celery.Celery(name="app")
@app.task(bind=True)defnoop(self):
passdefgen():
#assert Falseyieldfrom (noop.si() foriinrange(10))
g=celery.group(gen())
# Uncomment this to see the correct behaviour - but you'll need a backend# running since that'll mean we acually have tasks to submit.#print(g.tasks)gs=g.skew()
r=g()
print(repr(r))
#4298 (comment) is correct in that this is breakage in _regen which has already been fixed in #4459 and #6112, but neither have been merged. I'd like to see the targeted fix pulled out of those PRs and merged to close this issue rather than waiting on the more complex PR to be done. I'll do that when I have some time in the next day or so.
Activity
auvipy commentedon Dec 19, 2017
could you plz check the master if it still exists?
allanlei commentedon Dec 28, 2017
Yes. Still happening as of 2547666
auvipy commentedon Jan 15, 2018
any workaround?
moggers87 commentedon Mar 29, 2018
I believe this is a bug in
celery.utils.functional.regen. Compare the outputs ofregenon 4.1.0 (which has this bug) and 3.1.25 (which doesn't):On Celery 4.1.0:
On Celery 3.1.25:
Looking at 9982773 it would appear that
__consumeddoesn't get updated inside__iter__.Doing
print(group)first makes things work as expected because__getitem__is called and populates__consumedcorrectly. Then subsequent calls to__iter__work as expected too.A more proper workaround is to either only pass lists and tuples to
group, or if you're using something likeTask.chunks, reassigntaskswith a list, e.g.:Finally, #4459 will (probably) fix this issue too. @auvipy would you mind adding tests for this bug into your PR? Or if you prefer, I can open a separate PR that addresses this issue only.
auvipy commentedon Mar 29, 2018
plz proceed with the tests
1 remaining item
mohsen-mahmoodi commentedon Nov 17, 2020
Same issue:
auvipy commentedon Nov 20, 2020
@maybe-sybr would be great if you could also take a look here when possible
maybe-sybr commentedon Dec 8, 2020
I traced this back to get repro on the originally reported versions as well as current master (420e393). Worth noting that I made the mistake of thinking it was fixed because I was printing the tasks in the group between steps in the MRTC in this issue's summary to see what was going on. Doing so concretises the generator underlying the
_regeninstance. Here's my new MRTC which needs a backend running for the task submission if the expected behaviour is to be observed:#4298 (comment) is correct in that this is breakage in
_regenwhich has already been fixed in #4459 and #6112, but neither have been merged. I'd like to see the targeted fix pulled out of those PRs and merged to close this issue rather than waiting on the more complex PR to be done. I'll do that when I have some time in the next day or so.fix: Make regen less greedy
Makes regen less greedy
Makes regen less greedy
Makes regen less greedy (#6589)
Makes regen less greedy (celery#6589)