def serve(self): sock = get_systemd_socket() if sock is None: sock = self.address.get_listening_socket() else: self.address = InheritedSocket(sock) log(20, 'Ready on %s', self.address) self.sockets.append(sock) try: while 1: if self.packer is not None: timeout = 0.0 else: timeout = None r, w, e = select.select(self.sockets, [], [], timeout) for s in r: if s is sock: # new connection conn, addr = s.accept() self.address.set_connection_options(conn) self.clients.append(_Client(conn, addr)) self.sockets.append(conn) else: # command from client try: self.handle(s) except (ClientError, socket.error, socket.timeout, IOError): exc = sys.exc_info()[1] log(10, '%s', ''.join(map(str, exc.args))) self.sockets.remove(s) self.clients.remove(self._find_client(s)) s.close() if (self.packer is None and 0 < self.gcbytes <= self.bytes_since_pack): self.packer = self.storage.get_packer() if self.packer is not None: log(20, 'gc started at %s' % datetime.now()) if not r and self.packer is not None: try: pack_step = next(self.packer) if isinstance(pack_step, str): log(15, 'gc ' + pack_step) except StopIteration: log(20, 'gc at %s' % datetime.now()) self.packer = None # done packing self.bytes_since_pack = 0 # reset finally: self.address.close(sock)
def serve(self): sock = self.address.get_listening_socket() log(20, 'Ready on %s', self.address) self.sockets.append(sock) try: while 1: if self.packer is not None: timeout = 0.0 else: timeout = None r, w, e = select.select(self.sockets, [], [], timeout) for s in r: if s is sock: # new connection conn, addr = s.accept() self.address.set_connection_options(conn) self.clients.append(_Client(conn, addr)) self.sockets.append(conn) else: # command from client try: self.handle(s) except (ClientError, socket.error, socket.timeout, IOError): exc = sys.exc_info()[1] log(10, '%s', ''.join(map(str, exc.args))) self.sockets.remove(s) self.clients.remove(self._find_client(s)) s.close() if (self.packer is None and 0 < self.gcbytes <= self.bytes_since_pack): self.packer = self.storage.get_packer() if self.packer is not None: log(20, 'gc started at %s' % datetime.now()) if not r and self.packer is not None: try: pack_step = next(self.packer) if isinstance(pack_step, str): log(15, 'gc ' + pack_step) except StopIteration: log(20, 'gc at %s' % datetime.now()) self.packer = None # done packing self.bytes_since_pack = 0 # reset finally: self.address.close(sock)
def next_name(self): """() -> str Return the next element in a sequence of names. Names returned have not been used, and they have not been returned by previous calls to this function. """ if self.unused_name_generator is None: def generate_unused_names(): for j in self.offset_map.gen_holes(): name = int8_to_str(j) if name not in self.memory_index: yield name # Now continue with values above those in the offset map. j = self.offset_map.get_array_size() while True: name = int8_to_str(j) if name not in self.memory_index: yield name j += 1 self.unused_name_generator = generate_unused_names() return next(self.unused_name_generator)