You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 6 #7324
Hey @liangpinglk 👋,
Thank you for opening an issue. We will get back to you as soon as we can.
Also, check out our Open Collective and consider backing us - every little helps!
We also offer priority support for our sponsors.
If you require immediate assistance please consider sponsoring us.
The solution I found was to handle that exception internally and go on with your life. Like try and except and ignore that exception
Reacted by Garrett Massman, Stéphane Busso, Alfred van der Heide, janw, Phillipe Monares, johnconnorquigley, Edgar Nova, Mingkit Wong, Jonah George, Egor Gorban and 17 more
Reacted by Nauman Afsar, Feuermurmel, 4ndy, Nikita Zagorskii, William David Edwards, y-krautsevich-smartvalor and Hoang Viet Ta
WorkerLostError: Worker exited prematurely: signal 15 (SIGTERM) Job: 11.
File "hkis/consumers.py", line 166, in answer
is_valid, message =await check_answer(
File "hkis/tasks.py", line 174, in check_answerreturnawait asyncio.get_running_loop().run_in_executor(
File "concurrent/futures/thread.py", line 52, in run
result =self.fn(*self.args, **self.kwargs)
File "hkis/tasks.py", line 172, in sync_celery_check_answerreturn check_answer_task.apply_async((answer,), expires=60).get()
File "celery/result.py", line 224, in getreturnself.backend.wait_for_pending(
File "celery/backends/asynchronous.py", line 223, in wait_for_pendingreturn result.maybe_throw(callback=callback, propagate=propagate)
File "celery/result.py", line 336, in maybe_throwself.throw(value, self._to_remote_traceback(tb))
File "celery/result.py", line 329, in throwself.on_ready.throw(*args, **kwargs)
File "vine/promises.py", line 234, in throw
reraise(type(exc), exc, tb)
File "vine/utils.py", line 30, in reraiseraise value
Happen that a process has been killed by the OOM killer.
Here's what I'm seeing from a systemd point of view after reproducing the issue:
hkis-celery.service: A process of this unit has been killed by the OOM killer.
worker: Warm shutdown (MainProcess)
[2023-04-20 09:09:17,070: ERROR/MainProcess] Process 'ForkPoolWorker-1' pid:1057626 exited with 'signal 15 (SIGTERM)'
[2023-04-20 09:09:17,288: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: signal 15 (SIGTERM) Job: 23.')
Traceback (most recent call last):
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/worker/worker.py", line 203, in start
self.blueprint.start(self)
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
step.start(parent)
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 365, in start
return self.obj.start()
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 332, in start
blueprint.start(self)
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/bootsteps.py", line 116, in start
step.start(parent)
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/worker/consumer/consumer.py", line 628, in start
c.loop(*c.loop_args())
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/worker/loops.py", line 97, in asynloop
next(loop)
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/kombu/asynchronous/hub.py", line 295, in create_loop
tick_callback()
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 1311, in on_poll_start
cycle_poll_start()
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 532, in on_poll_start
self._register_BRPOP(channel)
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 518, in _register_BRPOP
channel._brpop_start()
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/kombu/transport/redis.py", line 950, in _brpop_start
self.client.connection.send_command(*command_args)
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/redis/connection.py", line 841, in send_command
self._command_packer.pack(*args),
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/redis/connection.py", line 554, in pack
buff = SYM_EMPTY.join((SYM_STAR, str(len(args)).encode(), SYM_CRLF))
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/celery/apps/worker.py", line 299, in _handle_request
raise exc(exitcode)
celery.exceptions.WorkerShutdown: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/hkis-celery/venv/lib/python3.9/site-packages/billiard/pool.py", line 1265, in mark_as_worker_lost
raise WorkerLostError(
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 15 (SIGTERM) Job: 23.
hkis-celery.service: Failed with result 'oom-kill'.
I've run into this error when trying to roll forward from python 3.10.9 (which works fine). I get it with both 3.10.10 and 3.10.11:
celery: 5.2.7
billiard: 3.6.4.0
Django: 3.2.16 (LTS)
MacOS: 12.6.3
python: 3.10.9 works, 3.10.10 & 3.10.11 have the problem
Some celery tasks complete successfully (eg: sending email). However, it appears to be the first interaction with a Django model that triggers the problem. Here's the line in my code that generates the exception. task_model can be one of 2 different models that are tracking the processing task. task_id is valid and the .get() should return a single instance:
objc[70333]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[70333]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
[2023-05-08 20:00:04,742: ERROR/MainProcess] Process 'ForkPoolWorker-1' pid:70333 exited with 'signal 6 (SIGABRT)'
[2023-05-08 20:00:04,755: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: signal 6 (SIGABRT) Job: 0.')
Traceback (most recent call last):
File "/Users/richard/VirtualEnvs/ontheday_heroku_3.10.10/lib/python3.10/site-packages/billiard/pool.py", line 1265, in mark_as_worker_lost
raise WorkerLostError(
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 6 (SIGABRT) Job: 0.
[2023-05-08 20:43:00,037:
I'm running a project on Heroku which forces the use of psycopg2-binary instead of psycopg2. There was a recent update to v2.9.6 that was confusing me when I initially ran into the problem. Recent debugging has revealed the following:
Works: MacOS on Apple Silicon
Celery 5.2.7 with python 3.10.9 with psycopg2-binary 2.9.5
Does not work: MacOS on Apple Silicon
Celery 5.2.7 with python 3.10.9 with psycopg2-binary 2.9.6
Works: MacOS on Apple Silicon
Celery 5.2.7 with python 3.10.9 with psycopg2 2.9.6 (no -binary)
Also works: MacOS on Intel silicon
Celery 5.2.7 with python 3.10.9 with psycopg2-binary 2.9.6 (with -binary)
So, for some reason, celery with psycopg2-binary 2.9.6 on Apple silicon is causing problems.
Any ideas??
Hi,
I've run into this error when trying to roll forward from python 3.10.9 (which works fine). I get it with both 3.10.10 and 3.10.11:
celery: 5.2.7 billiard: 3.6.4.0 Django: 3.2.16 (LTS) MacOS: 12.6.3 python: 3.10.9 works, 3.10.10 & 3.10.11 have the problem
Some celery tasks complete successfully (eg: sending email). However, it appears to be the first interaction with a Django model that triggers the problem. Here's the line in my code that generates the exception. task_model can be one of 2 different models that are tracking the processing task. task_id is valid and the .get() should return a single instance:
objc[70333]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[70333]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
[2023-05-08 20:00:04,742: ERROR/MainProcess] Process 'ForkPoolWorker-1' pid:70333 exited with 'signal 6 (SIGABRT)'
[2023-05-08 20:00:04,755: ERROR/MainProcess] Task handler raised error: WorkerLostError('Worker exited prematurely: signal 6 (SIGABRT) Job: 0.')
Traceback (most recent call last):
File "/Users/richard/VirtualEnvs/ontheday_heroku_3.10.10/lib/python3.10/site-packages/billiard/pool.py", line 1265, in mark_as_worker_lost
raise WorkerLostError(
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 6 (SIGABRT) Job: 0.
[2023-05-08 20:43:00,037:
Reacted by rahilbhansali, Laurentiu Piciu, Dvir Segev and boreBoar
@richardbrockie I am encountering the same problem with MacOS on Apple Silicon, Celery 5.2.7 with python 3.9.16, psycopg2 2.9.6 and psycopg2 2.9.5 (which I tried after reading this post). I didn't bother to try using a binary version of psycopg2 for it is not advised to be used for development.
This problem only occurred after I updated SQLAlchemy (to 2.0 from 1.4) and other related libraries.
This problem didn't occur if I run the Celery worker inside a docker container in the same Mac.
@candleindark I also reported the problem in the psycopg2 repo: psycopg/psycopg2#1593, where they pointed out that this is likely to be due to how macOS forks processes. What OS are you running in your docker container? I'm pretty sure it won't be macOS?
After playing around on Saturday, I now have a satisfactory work-around. I've verified that the -binary of v2.9.6 works fine in my production Heroku deployment, so am now specifying different requirements based on the OS. I have updated to python 3.10.12 as part of my fiddling:
# different versions of psycopg2 for different platforms...
psycopg2==2.9.6; sys_platform == "darwin"
psycopg2-binary==2.9.6; sys_platform == "linux"
During this past weekend, I did manage to have both psycopg2 and psycopg2-binary v2.9.6 installed side-by-side in a venv which had me thinking at times that the non-binary was also having the same problem.
Later this year I'll be rolling forward from Django 3.2.x LTS to 4.2 and be able to move to psycopg3 which I expect to be better tested in all the possible development environments.
# Uncomment these lines to use a Postgres database. Both are needed, since in production
# (which uses Linux) we want to install from source, so that security updates from the
# underlying Heroku stack image are picked up automatically, thanks to dynamic linking.
# On other platforms/in development, the precompiled binary package is used instead, to
# speed up installation and avoid errors from missing libraries/headers.
#psycopg; sys_platform == "linux"
#psycopg[binary]; sys_platform != "linux"
@richardbrockie I am encountering the same problem with MacOS on Apple Silicon, Celery 5.2.7 with python 3.9.16, psycopg2 2.9.6 and psycopg2 2.9.5 (which I tried after reading this post). I didn't bother to try using a binary version of psycopg2 for it is not advised to be used for development.
This problem only occurred after I updated SQLAlchemy (to 2.0 from 1.4) and other related libraries.
This problem didn't occur if I run the Celery worker inside a docker container in the same Mac.
This problem is only effecting me in development when I don't run the Celery worker in a container in my Mac. I guess I will just start running the Celery worker in a container even in development from now on.
I think I will consider switching to Psycopg 3 as well. I just use Psycopg2 for my use of SQLAlchemy. I don't use it directly. Do you know if there is anything I need to pay attention to make the switch from Psycopg2 to Psycopg3?
Platform: macOS Ventura 13.4.1 Intel
Python 3.9.17 and 3.10.12
celery[redis]==5.2.7 and celery[redis]==5.3.1
objc[7037]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[7037]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
2023-07-04 16:11:12,075 | ERROR | MainProcess | Process 'ForkPoolWorker-2' pid:7037 exited with 'signal 6 (SIGABRT)'
2023-07-04 16:11:12,088 | ERROR | MainProcess | Task handler raised error: WorkerLostError('Worker exited prematurely: signal 6 (SIGABRT) Job: 0.')
Traceback (most recent call last):
File "/Users/user/project/.venv/lib/python3.9/site-packages/billiard/pool.py", line 1265, in mark_as_worker_lost
raise WorkerLostError(
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 6 (SIGABRT) Job: 0.
I found a workaround on stackoverflow:
Setting OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES before executing celery solves the issue with multiprocessing on macOS.
Reacted by Asif Saif Uddin {"Auvi":"অভি"}, Luis Vitor Zerkowski, Chidi Williams, Edward Louth, Nik Molnar, Xinyin Li, Lev Ostatnigrosh , Alexey Levchuk, lgusmaosantos, Louis and 13 more
I've been facing the same issue. I've upgraded to python 3.10 and celery 2.3.3 now. My python kept crashing and I thought it was a celery issue.
But @richardbrockie's observations helped. I was checking and downgrading all my packages except psycopg2-binary - I had 2.9.7 installed. On reverting back to 2.9.5 - the crash has stopped on my M1 Max (apple silicon mac - running OS Sonoma Public Beta).
So this works for me - python 3.10, celery 2.3.3 and psycopg2-binary 2.9.5.
Reacted by Asif Saif Uddin {"Auvi":"অভি"}, Olzhas Arystanov and JulianPinzaru
Multiprocess forking is inherently unstable and celery does not have a supported way to choose how processes are started. The solution we have come up with is to use pool=threads and manage our own out of process workers with set_start_method "spawn".
Is there any fix to this. I went with pool=solo and concurrency=1. But it comes with a disadvantage that tasks can't be revoked. My application requires certain tasks to be revoked on user signal.
I can only speak about the billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 6 (SIGABRT) Job: 0.. Job <NUM>
There's a SO post about it. The issue is caused by some unhandled expception in code which inherits from BaseException instead of Exception.
I have code running pyo3 runtime. When Rust code raises error, it's propagated to Python caller as pyo3_runtime.PanicException which according the documentation inherits directly from BaseException, which is reserved for System exceptions.
Celery expects some attributes for custom exception to have and therefore fails to propagate the custom exception and instead raises billiard.exceptions.WorkerLostError.
Solution is to try/except around the code block that causes the unhandled exception and raise your own exception inheriting from Exception.
classYourCustomError(Exception):
def__init__(self, v):
super().__init__(v) # this is important I think.try:
yieldexceptBaseExceptionasexc:
raiseYourCustomError("msg") fromexc
For anyone else coming across this: one of my tasks was raising an exception inheriting from BaseException rather than Exception, causing WorkerLostError.
Reacted by Asif Saif Uddin {"Auvi":"অভি"} and mcursa-jwt
For anyone else coming across this: one of my tasks was raising an exception inheriting from BaseException rather than Exception, causing WorkerLostError.
Activity
open-collective-bot commentedon Feb 25, 2022
Hey @liangpinglk 👋,
Thank you for opening an issue. We will get back to you as soon as we can.
Also, check out our Open Collective and consider backing us - every little helps!
We also offer priority support for our sponsors.
If you require immediate assistance please consider sponsoring us.
liangpinglk commentedon Feb 25, 2022
I found that this problem had been discussed for a long time,but it still exists now,how can i fix it?(I need multiprocess)
#2958
https://groups.google.com/g/celery-users/c/E1kYCQySzuE?pli=1
https://stackoverflow.com/questions/56767461/celery-workerlosterror-worker-exited-prematurely-signal-6-sigabrt
nadzhou commentedon Dec 4, 2022
The solution I found was to handle that exception internally and go on with your life. Like try and except and ignore that exception
JulienPalard commentedon Apr 20, 2023
Got it today as:
Worker exited prematurely: signal 15 (SIGTERM)with:
Stack trace:
Happen that a process has been killed by the OOM killer.
Here's what I'm seeing from a systemd point of view after reproducing the issue:
richardbrockie commentedon May 9, 2023
Hi,
I've run into this error when trying to roll forward from python 3.10.9 (which works fine). I get it with both 3.10.10 and 3.10.11:
celery: 5.2.7
billiard: 3.6.4.0
Django: 3.2.16 (LTS)
MacOS: 12.6.3
python: 3.10.9 works, 3.10.10 & 3.10.11 have the problem
Some celery tasks complete successfully (eg: sending email). However, it appears to be the first interaction with a Django model that triggers the problem. Here's the line in my code that generates the exception.
task_modelcan be one of 2 different models that are tracking the processing task.task_idis valid and the .get() should return a single instance:begin_processing_task = task_model.objects.get(id=task_id)here's the exception:
richardbrockie commentedon Jun 14, 2023
Some more detail on this problem.
I'm running a project on Heroku which forces the use of psycopg2-binary instead of psycopg2. There was a recent update to v2.9.6 that was confusing me when I initially ran into the problem. Recent debugging has revealed the following:
Works: MacOS on Apple Silicon
Does not work: MacOS on Apple Silicon
Works: MacOS on Apple Silicon
Also works: MacOS on Intel silicon
So, for some reason, celery with psycopg2-binary 2.9.6 on Apple silicon is causing problems.
Any ideas??
candleindark commentedon Jun 27, 2023
@richardbrockie I am encountering the same problem with MacOS on Apple Silicon, Celery 5.2.7 with python 3.9.16, psycopg2 2.9.6 and psycopg2 2.9.5 (which I tried after reading this post). I didn't bother to try using a binary version of psycopg2 for it is not advised to be used for development.
This problem only occurred after I updated SQLAlchemy (to 2.0 from 1.4) and other related libraries.
This problem didn't occur if I run the Celery worker inside a docker container in the same Mac.
richardbrockie commentedon Jun 27, 2023
@candleindark I also reported the problem in the psycopg2 repo: psycopg/psycopg2#1593, where they pointed out that this is likely to be due to how macOS forks processes. What OS are you running in your docker container? I'm pretty sure it won't be macOS?
After playing around on Saturday, I now have a satisfactory work-around. I've verified that the
-binaryof v2.9.6 works fine in my production Heroku deployment, so am now specifying different requirements based on the OS. I have updated to python 3.10.12 as part of my fiddling:During this past weekend, I did manage to have both psycopg2 and psycopg2-binary v2.9.6 installed side-by-side in a venv which had me thinking at times that the non-binary was also having the same problem.
Later this year I'll be rolling forward from Django 3.2.x LTS to 4.2 and be able to move to psycopg3 which I expect to be better tested in all the possible development environments.
Heroku's example app (which looks up-to-date) seems to support my suspicion where they have this: https://github.com/heroku/python-getting-started/blob/main/requirements.txt.
candleindark commentedon Jun 27, 2023
@richardbrockie My docker container is running Debian 11.
This problem is only effecting me in development when I don't run the Celery worker in a container in my Mac. I guess I will just start running the Celery worker in a container even in development from now on.
I think I will consider switching to Psycopg 3 as well. I just use Psycopg2 for my use of SQLAlchemy. I don't use it directly. Do you know if there is anything I need to pay attention to make the switch from Psycopg2 to Psycopg3?
Thanks
frisia-mtz commentedon Jul 4, 2023
Encountering the same issue.
Platform: macOS Ventura 13.4.1 Intel
Python 3.9.17 and 3.10.12
celery[redis]==5.2.7 and celery[redis]==5.3.1
I found a workaround on stackoverflow:
Setting
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YESbefore executing celery solves the issue with multiprocessing on macOS.rahilbhansali commentedon Aug 31, 2023
I've been facing the same issue. I've upgraded to python 3.10 and celery 2.3.3 now. My python kept crashing and I thought it was a celery issue.
But @richardbrockie's observations helped. I was checking and downgrading all my packages except psycopg2-binary - I had 2.9.7 installed. On reverting back to 2.9.5 - the crash has stopped on my M1 Max (apple silicon mac - running OS Sonoma Public Beta).
So this works for me - python 3.10, celery 2.3.3 and psycopg2-binary 2.9.5.
24 remaining items
JulianPinzaru commentedon Oct 11, 2024
Ran into this issue recently as well.
My temporary fix was to use --pool=threads
celery -A proj worker --pool=threadsHowever, it would be preferable to have similar multiprocessing in a local dev environment...
JulianPinzaru commentedon Oct 11, 2024
Has anyone found any better way to address it ?
limFakson commentedon Dec 29, 2024
Does this problem have a solution ??
rkuo-danswer commentedon Dec 30, 2024
Multiprocess forking is inherently unstable and celery does not have a supported way to choose how processes are started. The solution we have come up with is to use pool=threads and manage our own out of process workers with set_start_method "spawn".
auvipy commentedon Feb 3, 2025
Anyone commenting should check this first
Cracker051 commentedon Feb 10, 2025
This link doesn't exist. It returns a 404 error. Could you explain what the problem was? My celery often raises a "Worker Exited Permanently
dibya-jena commentedon Mar 4, 2025
Is there any fix to this. I went with pool=solo and concurrency=1. But it comes with a disadvantage that tasks can't be revoked. My application requires certain tasks to be revoked on user signal.
ondrej-ivanko commentedon Mar 6, 2025
I can only speak about the
billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 6 (SIGABRT) Job: 0.. Job <NUM>There's a SO post about it. The issue is caused by some unhandled expception in code which inherits from
BaseExceptioninstead ofException.I have code running pyo3 runtime. When Rust code raises error, it's propagated to Python caller as
pyo3_runtime.PanicExceptionwhich according the documentation inherits directly from BaseException, which is reserved for System exceptions.Celery expects some attributes for custom exception to have and therefore fails to propagate the custom exception and instead raises
billiard.exceptions.WorkerLostError.Solution is to try/except around the code block that causes the unhandled exception and raise your own exception inheriting from
Exception.WilliamDEdwards commentedon Aug 11, 2025
For anyone else coming across this: one of my tasks was raising an exception inheriting from
BaseExceptionrather thanException, causingWorkerLostError.ondrej-ivanko commentedon Aug 12, 2025
exactly