Concurrent async worker for Django Tasks (django-tasks)
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_tasks_concurrent-0.1.0.tar.gz.
File metadata
- Download URL: django_tasks_concurrent-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34bf5b891f6095f059368992475905aa118b510b0132fbcf07143dba59b6978a
|
|
| MD5 |
57e528be3fecdd3090e70bfb58b18b78
|
|
| BLAKE2b-256 |
46e04cc60596651a98660a6b8882fce4ad73c72d5bf466b11ebb67a52c57cadf
|
File details
Details for the file django_tasks_concurrent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_tasks_concurrent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
204c3c1a9286846060c25bdffa202742f4e0afb3677f82115206747809495f73
|
|
| MD5 |
822c638130fc8328625890367a661776
|
|
| BLAKE2b-256 |
01f196f19505d8961759c16ccceb5a38b2959d0ed55cab82de773dcc7b4cf13e
|