Skip to content

WIP: Support preloading modules in the fork server - #11178

Draft
tzifudzi wants to merge 2 commits into
celery:mainfrom
tzifudzi:forkserver-preload
Draft

tzifudzi wants to merge 2 commits into
celery:mainfrom
tzifudzi:forkserver-preload

Conversation

@tzifudzi

@tzifudzi tzifudzi commented Nov 28, 2026 •

Copy link
Copy Markdown

PR is still in draft and not yet ready for review, awaiting dependant changes to be reviewed and merge first.

Part of enhancement Support forkserver as a worker_pool_start_method celery/celery#11096.

Problem

With forkserver, each pool child can end up importing the same application modules separately. Celery has no setting to select which modules the fork server should import once so its children can inherit them.

Solution

Add worker_forkserver_preload and --forkserver-preload to specify which modules the fork server imports before creating pool children. The list defaults to empty, and a non-empty list requires forkserver. Restart the whole worker to pick up changes to preloaded modules.

Configuration (celeryconfig.py)

worker_pool_start_method = "forkserver"
worker_forkserver_preload = ["myapp.models"]

CLI

celery -A myapp worker --pool-start-method=forkserver --forkserver-preload=myapp.models

Related PRs

Report the parent's fd numbers from forkserver pool workers celery/billiard #483
Restart the fork server if it dies celery/billiard #484
Replace the fork server on pool restart celery/billiard #485
Support forkserver as a prefork start method celery/celery #11177

Until the start-method PR merges, this draft also shows its changes. The preload changes are in commit 55d104a96.

Expose forkserver through the worker setting and CLI on Linux and macOS. Leave application preloading disabled and cover task dispatch after the pool has used all its children.

Part of celery#11096.
Allow prefork workers using forkserver to choose modules to import before workers start. Keep an empty preload list as the default and document that preloaded code is refreshed by a full worker restart.

Part of celery#11096.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant