1#!/usr/bin/env python 2 3# This Source Code Form is subject to the terms of the Mozilla Public 4# License, v. 2.0. If a copy of the MPL was not distributed with this 5# file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7from __future__ import absolute_import 8 9import signal 10 11 12class SignalHandler: 13 14 def __init__(self): 15 signal.signal(signal.SIGINT, self.handle_signal) 16 signal.signal(signal.SIGTERM, self.handle_signal) 17 18 def handle_signal(self, signum, frame): 19 raise SignalHandlerException("Program aborted due to signal %s" % signum) 20 21 22class SignalHandlerException(Exception): 23 pass 24