diff --git a/conda-store-server/conda_store_server/worker/tasks.py b/conda-store-server/conda_store_server/worker/tasks.py index eaa0b1be6..6441921d9 100644 --- a/conda-store-server/conda_store_server/worker/tasks.py +++ b/conda-store-server/conda_store_server/worker/tasks.py @@ -1,10 +1,11 @@ import datetime import os import shutil +import sys import typing import yaml -from celery import Task, shared_task +from celery import Task, platforms, shared_task from celery.execute import send_task from celery.signals import worker_ready from conda_store_server import api, environment, schema, utils @@ -44,6 +45,17 @@ def worker(self): self._worker.initialize() + # Installs a signal handler that terminates the process on Ctrl-C + # (SIGINT) + # Note: the following would not be enough to terminate beat and other + # tasks, which is why the code below explicitly calls sys.exit + # > from celery.apps.worker import install_worker_term_hard_handler + # > install_worker_term_hard_handler(self._worker, sig='SIGINT') + def _shutdown(*args, **kwargs): + return sys.exit(1) + + platforms.signals["INT"] = _shutdown + return self._worker