def serve_forever(self, poll_interval=0.1): self.__is_shut_down.clear() try: while not self.__shutdown_request: r, w_, e_ = select.select([self.socket], [], [], poll_interval) if self.socket in r: connection, client_address = self.socket.accept() t = basethread.BaseThread( "TCPConnectionHandler (%s: %s:%s -> %s:%s)" % ( self.__class__.__name__, client_address[0], client_address[1], self.address[0], self.address[1], ), target=self.connection_thread, args=(connection, client_address), ) t.setDaemon(1) try: t.start() except threading.ThreadError: self.handle_error(connection, client_address) connection.close() finally: self.__shutdown_request = False self.__is_shut_down.set()
def test_basethread(): t = basethread.BaseThread('foobar') assert re.match(r'foobar - age: \d+s', t._threadinfo())