Commit 2fc19287 authored by James Clark's avatar James Clark
Browse files

added signal handler and PID printing

parent 195bd296
......@@ -29,6 +29,7 @@ import os
import sys
import time
import yaml
import signal
import argcomplete
......@@ -39,7 +40,6 @@ from ligo_rucio.diskcache import DiskCacheFile
SUCCESS = 0
FAILURE = 1
LOGGER = logging.getLogger('user')
def setup_logger(logger):
......@@ -75,6 +75,15 @@ def setup_logger(logger):
setup_logger(LOGGER)
def signal_handler(sig, frame):
"""
Catch interrupts
"""
LOGGER.critical('Interrupt received')
os.kill(os.getpid(), signal.SIGTERM)
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
def get_parser():
"""
Command line parser
......@@ -447,6 +456,11 @@ def main():
# Identify which command to execute
command = commands.get(args.which)
# Print PID and write to file
LOGGER.info("%s lauched with PID %d", os.path.basename(__file__), os.getpid())
with open("{0}_pid".format(os.path.basename(__file__)), 'w') as pidfile:
pidfile.write(str(os.getpid()))
# Execute sub-command with argparser input
result = command(args)
......
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