forked from Schrolli91/BOSWatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignalHandler.py
32 lines (25 loc) · 867 Bytes
/
signalHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#
"""
TERM-Handler for use script as a daemon
In order for the Python program to exit gracefully when the TERM signal is received,
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
@param _signo: signal number
@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.
signal.signal(signal.SIGTERM, sigterm_handler)