Allow worker_pool_start_method='spawn' with the asynchronous prefork pool - #10584
Merged
Conversation
…pool The check added in celery#10339 rejected 'spawn' whenever the worker uses an event loop, assuming AsynPool could not work with spawned children. It does: the fd numbers the children report back to the parent survive spawnv_passfds, and the pool behaves the same as with fork, including replacement after a hard time limit. The check was also keyed off use_eventloop rather than the pool class, so it rejected -P solo and -P threads with an async transport as well. Remove it, update the CLI help and docs, and add smoke tests that run the worker with spawn against the smoke brokers.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10584 +/- ##
==========================================
+ Coverage 88.91% 88.95% +0.03%
==========================================
Files 153 153
Lines 20106 20104 -2
Branches 2364 2363 -1
==========================================
+ Hits 17877 17883 +6
+ Misses 1923 1919 -4
+ Partials 306 302 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
auvipy
self-requested a review
September 9, 2026 09:35
auvipy
reviewed
Sep 9, 2026
4 tasks
auvipy
approved these changes
Sep 9, 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.
Summary
Follow-up to #10339, as discussed there. Related: #6036 (spawn support has been requested there since 2020; with this change it is available for both prefork pool implementations).
#10339 rejects
worker_pool_start_method='spawn'whenever the worker uses an event loop, on the assumption that the asynchronous prefork pool cannot work with spawned children. In practice it does: I ran AsynPool with spawned children on Linux and macOS with hard and soft time limits, worker replacement after a hard time limit,--autoscale,--max-tasks-per-child,acks_late+task_reject_on_worker_lost,revoke(terminate=True),pool_restart, grow/shrink, chains/groups/chords, ETA/retry, large payloads and warm/cold shutdown, without a difference to fork (details in #10339 (comment)). The wiring the PR description worried about — the child reportinginqW_fdback to the parent — holds up becausespawnv_passfdspreserves fd numbers.The check also had a side effect: it keyed off
w.use_eventlooprather than the pool class, so-P soloand-P threadswith an async transport were rejected too.This PR:
Pool.create(), sospawnworks with both prefork pool implementations (and no longer blocks solo/threads);worker_proc_alive_timeout;worker_pool_start_method = "spawn"against the smoke brokers (AsynPool): tasks run inSpawnPoolWorker-*children, and the pool keeps working after a hard time limit kill.Testing
test_create_spawn_with_async_poolnow asserts the pool is created withforking_enable=False).--pool-start-method spawnat-c 2, hard time limit replacement and 50 tasks;-P solo --pool-start-method spawnnow starts.