Python 中的非阻塞 Thrift 服务器
在下面的代码片段中,我试图用 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'
In below code snippet, I am trying to make a non-blocking thrift server in 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()
I am getting the following error when the python client attempts to connect the server having tyhe above code snippet. Could you please tell me what can be causing this error? Probably I am missing something.
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了一些 工作 Thrift 代码 看起来你的 tfactory 需要是 TBufferedTransportFactory 而不是 TBufferedTransport 实例。
I found some working Thrift code and it looks like your tfactory needs to be a TBufferedTransportFactory and not a TBufferedTransport instance.