Skip to content

Running async tasks in parallel #138

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

Open
adnathanail opened this issue Feb 24, 2025 · 4 comments
Open

Running async tasks in parallel #138

adnathanail opened this issue Feb 24, 2025 · 4 comments
Labels
database-backend Issues relating to the database backend
Milestone

Comments

@adnathanail
Copy link

Really love this package! Can't wait to see it land in Django core

I was wondering if it was possible to run tasks in parallel?

I have some slow network calls which I call asynchronously, but tasks are still executed sequentially. Is it possible to start processing the next task while awaiting a call in a previous one?

@RealOrangeOne
Copy link
Owner

Currently no - each process runs just a single task concurrently. If you need to run multiple tasks at once, you'll need to run multiple worker processes.

It's something I think it would be great to support, particularly for async tasks, but working out the behaviour, especially when relating to non-async tasks is complex.

See also this discussion: #117

@RealOrangeOne RealOrangeOne added the database-backend Issues relating to the database backend label Feb 24, 2025
@RealOrangeOne RealOrangeOne added this to the Some Day milestone Feb 24, 2025
@adnathanail
Copy link
Author

Ahh gotcha! Ok thank you

@oliverhaas
Copy link

oliverhaas commented Mar 21, 2025

[...] especially when relating to non-async tasks is complex.

Can you give a brief explanation or pointer what you mean with that?
Having a sync task in the mix would be blocking other tasks, even if all other tasks are async, but that could also happen if all tasks are completely async. Also, I'm not sure if there is a clean way to just use threads instead of an event loop. Anything that adds some concurrency without spawning full processes (and exploding memory requirements) sounds fine to me.

@RealOrangeOne
Copy link
Owner

There are certain features which may require child processes for tasks (eg timeouts for sync tasks). So the only way to achieve proper concurrency is to do process-based. The more complexity in the worker process, the harder it is to reason about what it's doing.

I could see an argument for an async-only worker command, which only handles async tasks, and thus has massively improved throughput. But that's a future aspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database-backend Issues relating to the database backend
Projects
None yet
Development

No branches or pull requests

3 participants