예제 #1
0
 def __init__(self,
              processor,
              lsocket,
              inputProtocolFactory=None,
              outputProtocolFactory=None,
              threads=10,
              readTimeout=None,
              maxQueueSize=0):
     self.processor = self._getProcessor(processor)
     self.socket = lsocket
     self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory()
     self.out_protocol = outputProtocolFactory or self.in_protocol
     self.threads = int(threads)
     self.clients = {}
     self.max_queue_size = maxQueueSize  # do not set this as a hard size
     # maximum - the queue may need
     # extra space for close()
     self.tasks = Queue.Queue()
     self._read, self._write = _create_socketpair()
     self.prepared = False
     self._stop = False
     self.serverEventHandler = TServer.TServerEventHandler()
     self.select_timeout = DEFAULT_SELECT_TIMEOUT
     self.poller = TSocket.ConnectionEpoll() if hasattr(select, "epoll") \
             else TSocket.ConnectionSelect()
     self.last_logged_error = 0
     timeouts = [x for x in [self.select_timeout, readTimeout] \
                     if x is not None]
     if len(timeouts) > 0:
         self.select_timeout = min(timeouts)
     self._readTimeout = readTimeout
예제 #2
0
    def test_poller_process(self):
        # Make sure that pollers do not fail when they're given None as timeout
        text = "hi"  # sample text to send over the wire
        with TSocket.TServerSocket(port=0, family=socket.AF_INET6) as server:
            addr = server.getSocketNames()[0]

            def write_data():
                # delay writing to verify that poller.process is waiting
                time.sleep(1)
                with TSocket.TSocket(host=addr[0], port=addr[1]) as conn:
                    conn.write(text)

            poller = TSocket.ConnectionSelect()
            thread = threading.Thread(target=write_data)
            thread.start()
            for filenos in server.handles.keys():
                poller.read(filenos)

            r, _, x = poller.process(timeout=None)

            thread.join()
            # Verify that r is non-empty
            self.assertTrue(r)