Skip to content

Commit

Permalink
Revert "Revert "Added handle of SIGTERM in BaseTask in celery/task.py…
Browse files Browse the repository at this point in the history
… to prevent kill the task" (#5577)" (#5586)

This reverts commit a9dc166.
  • Loading branch information
auvipy authored Jun 13, 2019
1 parent c276885 commit f79894e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions celery/app/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Task implementation: request context and the task base class."""
from __future__ import absolute_import, unicode_literals

import signal
import sys

from billiard.einfo import ExceptionInfo
Expand All @@ -20,6 +21,7 @@
from celery.utils import abstract
from celery.utils.functional import mattrgetter, maybe_list
from celery.utils.imports import instantiate
from celery.utils.log import get_logger
from celery.utils.nodenames import gethostname
from celery.utils.serialization import raise_with_context

Expand Down Expand Up @@ -386,6 +388,10 @@ def add_around(cls, attr, around):
setattr(cls, attr, meth)

def __call__(self, *args, **kwargs):
logger = get_logger(__name__)
handle_sigterm = lambda signum, frame: \
logger.info('SIGTERM received, waiting till the task finished')
signal.signal(signal.SIGTERM, handle_sigterm)
_task_stack.push(self)
self.push_request(args=args, kwargs=kwargs)
try:
Expand Down

0 comments on commit f79894e

Please sign in to comment.