Commit b2f8fbba authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

SIGTERM (kill/pkill commands) is now properly handled (locks are closed, etc.).

parent ddfe3836
......@@ -353,8 +353,10 @@ class process_controller(object):
"""
Run all processors at once.
"""
signal.signal(signal.SIGINT, self.stop) # enable clean shutdown possibility
# enable clean shutdown possibility
# NOTE: a signal.SIGKILL (kill -9 ...) forces to kill the process and cannot be catched or handled
signal.signal(signal.SIGINT, self.stop) # catches a KeyboardInterrupt
signal.signal(signal.SIGTERM, self.stop) # catches a 'kill' or 'pkill'
# noinspection PyBroadException
try:
......@@ -422,7 +424,10 @@ class process_controller(object):
raise
def run_all_processors(self, custom_data_list=None):
signal.signal(signal.SIGINT, self.stop) # enable clean shutdown possibility
# enable clean shutdown possibility
# NOTE: a signal.SIGKILL (kill -9 ...) forces to kill the process and cannot be catched or handled
signal.signal(signal.SIGINT, self.stop) # catches a KeyboardInterrupt
signal.signal(signal.SIGTERM, self.stop) # catches a 'kill' or 'pkill'
# noinspection PyBroadException
try:
......@@ -506,13 +511,16 @@ class process_controller(object):
def stop(self, signum, frame):
"""Interrupt the running process controller gracefully."""
self.logger.warning('Process controller stopped by user. Shutting down gracefully...')
self.config.status = 'canceled'
self.update_DB_job_record()
self.shutdown()
self.logger.warning('Process controller stopped by user.')
raise KeyboardInterrupt # terminate execution and show traceback
if signum == 2:
raise KeyboardInterrupt('Received a KeyboardInterrupt.') # terminate execution and show traceback
elif signum == 15:
raise SystemExit('Received a SIGTERM command.')
def shutdown(self):
"""Shutdown the process controller instance (loggers, remove temporary directories, ...)."""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment