Repository navigation
Description
Checklist
- I have checked the issues list
for similar or identical feature requests. - I have checked the pull requests list
for existing proposed implementations of this feature. - I have checked the commit log
to find out if the if the same feature was already implemented in the
master branch. - I have included all related issues and possible duplicate issues
in this issue (If there are none, check this box anyway).
Related Issues and Possible Duplicates
Related Issues
- None
Possible Duplicates
Similar to issue #5005 and issue #5021
Brief Summary
When launching child processes, celery uses the fork method. Sometimes it is preferable to be able to spawn rather than fork, for instance: https://bugs.python.org/issue33725. Celery 3.x had this ability with the CELERYD_FORCE_EXECV option, however it was apparently removed in version 4.0 for some reason ( https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html). Please re-introduce this feature.
Design
Architectural Considerations
None
Proposed Behavior
This feature would behave exactly as it (presumably) did in version 3.x: using spawn to launch child workers rather than fork. It is likely this is already the behavior when run on windows anyway, since at least in the python multiprocessing module fork is not available on windows.
Proposed UI/UX
Same as in version 3.x: provide a CELERYD_FORCE_EXECV option (although I guess it would be lowercase now)
Diagrams
N/A
Alternatives
None
Activity
georgexsh commentedon May 24, 2020
I think celery should defer
init_workercall inside the worker process with the prefork pool, which will resolve this and many other issues together.(following message is copied from a celery-users mailing list thread: https://groups.google.com/d/msgid/celery-users/468ff21a-afd1-4887-ab9a-b7e548501e65%40googlegroups.com?utm_medium=email&utm_source=footer)
currently, on platform supports
fork(), andpreforkpool is used,app.loader.init_worker(fromAppLoader) is called in the master process, which is very annoying.init_workerwill import app task modules, as app task modules are imported inside the master process, user application code is executed there then master forked worker, but not all the application code or library is prepared for a fork call, generally, they are multithreading safe, but not fork safe.take the Queue(queue in py3) stdlib(!!) for example, if the application created a Queue instance, then process forked, deadlock happened in the child process if the Queue instance gets used, as the mutex inside Queue is not fork-safe.
https://groups.google.com/forum/#!topic/sqlalchemy/YX9NuBD75oY is a serious problem we have met also.
#496 is another example.
I think having the master process polluted with user application code before
fork()is a bad design, take gunicorn as a good example, it will not touch the user WSGI app code before the worker forked by default, but give the user the option to do so.auvipy commentedon May 24, 2020
thanks for chiming in. would you mind handling this?
georgexsh commentedon May 24, 2020
for now, I am trying to find a workaround for our application by subclassing
AppLoader, letinit_workerdo nothing in the master process if the prefork pool is used becauseprocess_initializerwould triggerinit_workeragain in the worker process anyway.@auvipy do you think this could be polished as a formal solution?
the problem is, so far I can't find a sound way to tell the difference between master and worker. environ variable like
_MP_FORK_LOGFILE_is not a reliable source I think. maybe I should go to check the parent process title?auvipy commentedon May 24, 2020
please dig deeper. i will need some time to revisit this
georgexsh commentedon May 25, 2020
a quick and dirty demo:
xirdneh commentedon May 25, 2020
@georgexsh I think this looks like a good solution to explore.
Have you been able to test this locally?
I'm curious to see if the master process brakes in some way.
georgexsh commentedon May 26, 2020
auvipy commentedon May 26, 2020
would you mind come with a PR?
georgexsh commentedon May 26, 2020
@auvipy not yet, it misses worker pool class checking which I have no clue, and, it is unclear to me where should the patch goes, do you think it should be the default behavior of
AppLoader, or as an option?georgexsh commentedon May 26, 2020
besides, dependent on a non-std API
p._parent_pidis not a good idea to me, billiard should expose an API to indicate the current process is a worker.xirdneh commentedon May 26, 2020
@georgexsh I think it would be a good idea to open up a PR and work on those things. I can lend a hand if you want.
Also, that is if you have time to keep an eye of this PR.
Having said that let me ask a few questions:
georgexsh commentedon May 27, 2020
45 remaining items
stuaxo commentedon Aug 29, 2025
When it comes to PsycoPg (as used in the Celery+Django+Postgres) combination, it was kerberos auth that was triggering this (most of the time), and a fix is being added there to disable that when it's not being used.
This should help somewhat until sparn is available here.
psycopg/psycopg#1136
IngmarStein commentedon Sep 27, 2025
I've started seeing paperless-ngx's Celery worker crash after updating to macOS 26.0 (still the same in 26.1 beta 1) which may trigger another fork-unsafe call. A workaround is to use any other pool type than the default
prefork.Here's a stacktrace:
Nusnus commentedon Feb 26, 2026
Potential fix:
Released in billiard v4.3.0rc1
auvipy commentedon Jul 5, 2026
This pr #10339 might be a potential fix for this, need people to check and try this
auvipy commentedon Sep 9, 2026
another relevant pr #10584
ShaheedHaque commentedon Sep 10, 2026
@auvipy Could you kindly summarise here, or with a pointer to the docs, how to enable this? (with or without async?)
auvipy commentedon Sep 10, 2026
please wait until the pre release of v5.7