Python中的非阻塞Thrift服务器

F. *_*mir 5 python thrift nonblocking thrift-protocol

在下面的代码片段中,我试图在python中创建一个非阻塞的thrift服务器.

    # set handler to our implementation
    handler = ServiceHandler()

    processor = MyService.Processor(handler)
    transport = TSocket.TServerSocket(port=port)
    tfactory = TTransport.TFramedTransport(transport)  
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()

    # set server
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)

    print 'Python Server has started listening on port ' + str(port)
    print '################################################'
    server.serve()
Run Code Online (Sandbox Code Playgroud)

当python客户端尝试连接具有上述代码片段的服务器时,我收到以下错误.你能告诉我导致这个错误的原因吗?可能我错过了一些东西.

    Exception in thread Thread-1:
    Traceback (most recent call last):
    File "/usr/lib64/python2.6/threading.py", line 522, in __bootstrap_inner
    self.run()
    File "/usr/lib64/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
    File "/usr/local/lib64/python2.6/site-packages/thrift/server/TServer.py", line 114, in handle
    itrans = self.inputTransportFactory.getTransport(client)
    AttributeError: TFramedTransport instance has no attribute 'getTransport'
Run Code Online (Sandbox Code Playgroud)

And*_*lke 9

我找到了一些有效的Thrift代码,看起来你的tfactory需要是TBufferedTransportFactory而不是TBufferedTransport实例.

tfactory = TTransport.TBufferedTransportFactory()
Run Code Online (Sandbox Code Playgroud)