Repository navigation
Add --threads to run several tasks at once inside a worker - #61
Merged
Merged
Conversation
The worker stays one process with one polling thread, which still fetches, receives from the broker and handles the signals; the task it found is handed to one of M executor threads instead of being run inline. The claim is made by the polling thread with the executor's worker id, so the next fetch never hands out the same row, and a broker receive asks for no more messages than there are idle threads. Each thread records its own id on the tasks it runs, has a database connection of its own and closes old connections after every task. --max-tasks counts the tasks handed out, failures are counted across the threads under a lock, and on SIGTERM the tasks in the threads finish before the worker exits. Several threads are refused on SQLite, as several workers are: claims from the broker path and finishing writes from several threads collide on the database lock. The default of 1 leaves the loop as it was. Refs #25
tokibito
force-pushed
the
threads-option
branch
from
October 2, 2026 05:17
d273f10 to
3b49662
Compare
This was referenced Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second step of #25, on top of the
claim_task()/run_claimed_task()split from #60.--threads Mruns M tasks at once inside one worker process.What it does
The worker stays one process with one polling thread. That thread still does what it did: it fetches from the database, receives from the broker and handles the signals. What changes is that the task it found goes to one of M executor threads instead of being run inline, so M tasks are in progress while the polling load stays at one fetch per `--interval`.
Two things to look at
Documentation
The README's Running several workers gains a third row in the tiers table, a `--threads M` section (thread safety is on the task code, I/O-bound only, memory but not connections, worker ids, shutdown and the cap, combining with `--workers`, SQLite), and a Threads instead bullet in Trade-offs. The help string is translated in the four catalogues. The CHANGELOG entry is under Unreleased; the default is 1, so existing projects need no changes.
Tests
Run on Python 3.13 / Django 6.0 (SQLite), Python 3.14 / Django 6.1 with `-W error::DeprecationWarning`, and the whole suite against PostgreSQL 16.
Refs #25