def SIGINT_handler(pid_file, socket_fd, sql_pool, signum, frame): logging.info("Caught SIGNAL 2. Exiting...") if os.path.exists(pid_file): try: os.remove(pid_file) except: logging.error("Error in first forking. Traceback: \n{0}\n".format(traceback.format_exc())) try: socket_fd.shutdown(socket.SHUT_RDWR) socket_fd.close() except: logging.error("Error in closing master socket. Traceback: \n{0}\n".format(traceback.format_exc())) try: PySQLPool.terminatePool() except: logging.error("Error in terminating SQL pool. Traceback: \n{0}\n".format(traceback.format_exc())) sys.exit(0)