Celery server not terminating immediately when using prefork and without pool line command

I'm working on a django project with celery and redis installed. When I run the Celery server as 'celery -A main_proj -l debug -P solo' or 'celery -A main_proj -l debug -P threads', I can terminate them just fine by just pressing CTRL-C once or twice for warm/cold shutdown. However, when I run Celery as 'celery -A main_proj -l debug' and 'celery -A main_proj -l debug -P prefork', whenever I try to terminate them, it just get stuck at Worker: Stopping Pool. No matter how long I wait, it stays like that until I decide to terminate it with taskkill. I'm fine with the first two alternatives but I want to know why the latter options don't finish quickly.

This is the code I have for my celery app:

from __future__ import absolute_import, unicode_literals
import os
from celery.schedules import crontab
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main_proj.settings')

app = Celery('main_proj')

app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

Additionally, withing the settings.py file I set the CELERY_BROKER_URL with a redis URL that I get from Railway and I have the following code within the init file for the main_proj folder:

from .celery import app as celery_app

__all__ = ('celery_app',)

This is what always happens whenever I try to terminate the Celery server before killing it with taskkill on a separate terminal.

Even when pressing CTRL+C multiple times, it still wouldn't terminate

Interestingly enough, when I start the celery server with either 'celery -A main_proj -l debug' or 'celery -A main_proj -l debug -P prefork', a bunch of functions, if I'm not mistaken, would appear on the console of my editor (which is Visual Studio Code that i'm using), and this is something that doesn't happen when I use solo nor threads for the pool line command. I'm not sure if maybe this could be the cause for why it's taking so long to terminate.

This is the list of functions that shows when I start the celery server

Any helpful explanation for this would be greatly appreciated.

Back to Top