def main(args): signal_fd = signalfd.init() with Main(args, NoLock) as service: try: context = zmq.Context() try: socket = context.socket(zmq.SUB) socket.bind(conf.get("zeromq", "bind")) socket.setsockopt(zmq.SUBSCRIBE, b"") service.init() poller = zmq.Poller() poller.register(socket, zmq.POLLIN) poller.register(signal_fd, zmq.POLLIN) try: flush_interval = conf.getint("backup", "interval") flush_time = 0 while True: timeout = flush_time + flush_interval - time.time() if timeout > 0: for x, mask in poller.poll(timeout * 1000): if mask & ~zmq.POLLIN: log.error("poll event: file=%r mask=0x%x", x, mask) if mask & zmq.POLLIN: if x == socket: handle_add(service, socket) elif x == signal_fd: if handle_signal(service): return else: service.flush() flush_time = time.time() finally: socket.close() finally: context.term() except: log.critical("terminated", exc_info=True)
def __init__(self): self.fd = signalfd.init() self.interval = conf.getint("backup", "interval")
def __init__(self, map=None): fd = signalfd.init() asyncore.file_dispatcher.__init__(self, fd, map)