def handle_read(self): fail = True try: signum = signalfd.read() if signum > 0: self.handle_signal(signum) fail = False finally: if fail: self.handle_close()
def handle_signal(service): num = signalfd.read() if num == signal.SIGINT: log.debug("SIGINT received") return True elif num == signal.SIGTERM: log.debug("SIGTERM received") return True elif num == signal.SIGHUP: log.info("reconfiguring") service.reconfigure() elif num == signal.SIGUSR1: log.debug("SIGUSR1 received") if conf.getboolean("debug", "force_cache_rotation", False): service.flush(force_rotate=True) elif num != signal.SIGCHLD: log.debug("signal %r ignored", num)
def sleep(self): """ Try to sleep until the configured timeout. @rtype Control.Condition """ start = time.time() while True: elapsed = time.time() - start timeout = self.interval - elapsed if timeout < 0: break try: rlist, wlist, xlist = select.select([self.fd], [], [], timeout) except select.error as e: if e.args[0] == errno.EINTR: continue else: raise if not rlist: return self.Condition.Timeout num = signalfd.read() if num is None: log.warning("EOF from signal fd") return self.Condition.Terminate if num == signal.SIGTERM: log.debug("SIGTERM received") return self.Condition.Terminate elif num == signal.SIGINT: log.debug("SIGINT received") return self.Condition.Terminate elif num == signal.SIGHUP: log.debug("SIGHUP received") return self.Condition.Hangup elif num == signal.SIGUSR1: log.debug("SIGUSR1 received") return self.Condition.User1 elif num != signal.SIGCHLD: log.debug("signal %d ignored", num)