django-tasks-concurrent
Concurrent async worker for Django Tasks.
Runs multiple async tasks concurrently using asyncio.TaskGroup. While one task awaits I/O (API calls, database queries), others can execute. Optimized for I/O-bound workloads.
Installation
pip install django-tasks-concurrent
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...
"django_tasks",
"django_tasks.backends.database",
"django_tasks_concurrent",
]
Usage
Run the worker:
# 3 concurrent workers (default)
python manage.py concurrent_worker
# 5 concurrent workers with 0.5s polling interval
python manage.py concurrent_worker --concurrency=5 --interval=0.5
# Specify queue and backend
python manage.py concurrent_worker --queue-name=high-priority --backend=default
Options
| Option | Default | Description |
|---|---|---|
--concurrency |
3 | Number of concurrent sub-workers |
--interval |
1.0 | Polling interval (seconds) when no tasks |
--queue-name |
settings.TASK_QUEUE_NAME or "default" |
Queue to process |
--backend |
"default" | Django Tasks backend name |
How It Works
The worker spawns N sub-workers as asyncio coroutines. Each sub-worker:
- Claims a task using
SELECT FOR UPDATE SKIP LOCKED - Executes the task (async tasks run natively, sync tasks via thread pool)
- Marks task as succeeded/failed
- Repeats
This allows true concurrent execution of async tasks - while one awaits an API response, others continue processing.
When to Use
Use concurrent_worker for:
- I/O-bound tasks (API calls, LLM inference, HTTP requests)
- Tasks that spend most time awaiting external services
- Workloads where you want N tasks running simultaneously
Use standard db_worker for:
- CPU-bound tasks
- Tasks that don't benefit from async
- Simple sequential processing
Async Task Example
from django_tasks import task
@task
async def call_llm_api(prompt: str) -> str:
async with httpx.AsyncClient() as client:
response = await client.post(
"https://api.anthropic.com/v1/messages",
json={"prompt": prompt},
)
return response.json()["content"]
With --concurrency=3, three LLM calls can be in-flight simultaneously.
Requirements
- Python 3.12+
- Django 6.0+
- django-tasks 0.5.0+
License
MIT
Metadata
Release files for django-tasks-concurrent 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_tasks_concurrent-0.3.1.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_tasks_concurrent-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.9 kB
Release files / django_tasks_concurrent-0.3.1.tar.gz
| Download URL | django_tasks_concurrent-0.3.1.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
381804ecd15ad5ee22277d5ab2407ec19c7a7c10ab8812cb041d272bb1f4e5c9
|
|
BLAKE2b-256 checksum How to use checksums |
0497433844ea2c6187b67feecef5feebcbd4392682e3d6e444777f69e241066e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / django_tasks_concurrent-0.3.1-py3-none-any.whl
| Download URL | django_tasks_concurrent-0.3.1-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ba148cc32f884e9fc92c2721c5993f7ff5d02598592f026ecf72227747ad7e6
|
|
BLAKE2b-256 checksum How to use checksums |
188723032577e1ecdc3dc4c954f89a0b1c8c1c105aecd19c64552877792041a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|