gpt4 book ai didi

python - Python 中的非阻塞 Thrift 服务器

转载 作者:太空狗 更新时间:2023-10-30 00:46:30 25 4
gpt4 key购买 nike

在下面的代码片段中,我试图在 python 中制作一个非阻塞的节俭服务器。

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

最佳答案

我找到了一些 working Thrift code并且看起来您的 tfactory 需要是 TBufferedTransportFactory 而不是 TBufferedTransport 实例。

tfactory = TTransport.TBufferedTransportFactory()

关于python - Python 中的非阻塞 Thrift 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8384326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com