Пример #1
0
 def serve_forever(self, poll_interval=0.1):
     self.__is_shut_down.clear()
     try:
         while not self.__shutdown_request:
             try:
                 r, w_, e_ = select.select([self.socket], [], [],
                                           poll_interval)
             except select.error as ex:  # pragma: no cover
                 if ex[0] == EINTR:
                     continue
                 else:
                     raise
             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('foobar - age: \d+s', t._threadinfo())