Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chord awaited even if not explicitly requested #8995

Open
11 of 18 tasks
emmepra opened this issue May 1, 2024 · 2 comments
Open
11 of 18 tasks

Chord awaited even if not explicitly requested #8995

emmepra opened this issue May 1, 2024 · 2 comments

Comments

@emmepra
Copy link

emmepra commented May 1, 2024

Checklist

  • I have verified that the issue exists against the main branch of Celery.
  • This has already been asked to the discussions forum first.
  • I have read the relevant section in the
    contribution guide
    on reporting bugs.
  • I have checked the issues list
    for similar or identical bug reports.
  • I have checked the pull requests list
    for existing proposed fixes.
  • I have checked the commit log
    to find out if the bug was already fixed in the main branch.
  • I have included all related issues and possible duplicate issues
    in this issue (If there are none, check this box anyway).
  • I have tried to reproduce the issue with pytest-celery and added the reproduction script below.

Mandatory Debugging Information

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).
  • I have verified that the issue exists against the main branch of Celery.
  • I have included the contents of pip freeze in the issue.
  • I have included all the versions of all the external dependencies required
    to reproduce this bug.

Optional Debugging Information

  • I have tried reproducing the issue on more than one Python version
    and/or implementation.
  • I have tried reproducing the issue on more than one message broker and/or
    result backend.
  • I have tried reproducing the issue on more than one version of the message
    broker and/or result backend.
  • I have tried reproducing the issue on more than one operating system.
  • I have tried reproducing the issue on more than one workers pool.
  • [ x I have tried reproducing the issue with autoscaling, retries,
    ETA/Countdown & rate limits disabled.
  • I have tried reproducing the issue after downgrading
    and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

  • None

Possible Duplicates

  • None

Behavior

My goal is to launch a chord from a FastAPI call, which creates N different Tasks to be executed, then not waiting for it to complete, just returning Response 200. To do so I first used the following notation:

header = [exec_calc.s(x) for x in args]
callback = do_checks.si() # no need for header results as argument here
chord(header)(callback)

Unfortunately it resulted in exploding FastAPI process and no return since chord completion, not desired. So I used this other notation hoping for a different ending:

header = [exec_calc.s(x) for x in args]
callback = do_checks.si() # no need for header results as argument here
chord(header, callback).async()

But still, same behavior happening: FastAPI process exploding and nothing returned.

It's not very clear to me how chord should be used and if they can actually be used asynchronously or not. Maybe there's some specific behavior not properly described in their documentation.

@AlexPetul
Copy link

This line chord(header, callback).async() is almost correct, however, chord does not define such method as async(). Use delay() or apply_async() instead. For example, that's how i used chord in combination with chain:

chord(
    run_vm_playbooks,  # Will run in parallel
    chain(
        terraform.refresh.si(),
        start_cloned_sandbox.si(),
    ),
).delay()

If you call chord object chord(...)(), you program will wait until it finishes the execution. Use one of those methods, mentioned earlier, depending on your requirements.

@emmepra
Copy link
Author

emmepra commented May 1, 2024

Thanks for the prompt feedback!
However .async() was actually a typo, I used .apply_async() in the second case but still it wasn't working as expected.
In particular header is a very big list (len(args) > 1.000.000) of exec_calc() tasks which should be run asynchronously then called back by callback.

I was expecting the group part of it running asynchronously as if been called by group(..).apply_async(), but it seems like it got stuck for some reason. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants