BOSWatch/includes/signalHandler.py

33 lines
868 B
Python
Raw Normal View History

2015-06-25 21:19:41 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
#
"""
TERM-Handler for use script as a daemon
2015-07-02 09:02:49 +02:00
In order for the Python program to exit gracefully when the TERM signal is received,
2015-06-25 21:19:41 +02:00
it must have a function that exits the program when signal.SIGTERM is received.
@author: Jens Herrmann
"""
import logging
import signal # for use as daemon
import sys # throw SystemExitException when daemon is terminated
def sigterm_handler(_signo, _stack_frame):
"""
TERM-Handler for use script as a daemon
@type _signo: signalnum
2015-07-02 09:02:49 +02:00
@param _signo: signal number
2015-06-25 21:19:41 +02:00
@type _stack_frame: frame object
@param _stack_frame: current stack frame
@exception: SystemExitException when daemon is terminated
"""
logging.warning("TERM signal received")
sys.exit(0)
# Set the handler for signal to the function handler.
2015-07-02 09:02:49 +02:00
signal.signal(signal.SIGTERM, sigterm_handler)