Skip to content

Commit

Permalink
Terminate worker tasks on SIGINT
Browse files Browse the repository at this point in the history
Fixes #707.
  • Loading branch information
nkaretnikov committed Jan 4, 2024
1 parent a4863e3 commit 0237f94
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion conda-store-server/conda_store_server/worker/tasks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 0237f94

Please sign in to comment.