diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index c91c7598ca7..5ee85ef8fc5 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -404,6 +404,15 @@ def run(self, version_pk): # pylint: disable=arguments-differ default_retry_delay=7 * 60, ) def update_docs_task(self, version_pk, *args, **kwargs): + import signal + + def sigterm_received(*args, **kwargs): + log.warning('SIGTERM received. Waiting for build to stop gracefully after it finishes.') + + # Do not send the SIGTERM signal to childs (pip is automatically killed when + # receives SIGTERM and make the build to fail one command and stop build) + signal.signal(signal.SIGTERM, sigterm_received) + try: step = UpdateDocsTaskStep(task=self) return step.run(version_pk, *args, **kwargs)