Python中的非阻塞Thrift服务器

5 投票
1 回答
5563 浏览
提问于 2025-04-17 07:43

在下面的代码片段中,我正在尝试用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()

当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'

1 个回答

9

我找到了一些可以用的Thrift代码,看起来你的tfactory应该是一个TBufferedTransportFactory,而不是一个TBufferedTransport实例。

tfactory = TTransport.TBufferedTransportFactory()

撰写回答