如何使用python和thrift处理Broken管道

时间:2018-05-18 01:19:40

标签: python thrift

我是关于thrift和socket的新手。我用python构建一个服务器服务器。这样的代码:

class HelloServiceHandler:
    def buildIndex(self, fileData):
        tem = index.SaveIndex(fileData.name)
        tem.build_index(3)
        return True

handler = HelloServiceHandler()
processor = ReIndex.Processor(handler)
transport = TSocket.TServerSocket("0.0.0.0", 9090)
tfactory = TTransport.TFramedTransportFactory()
pfactory = TCompactProtocol.TCompactProtocolFactory()

server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)

print ("Starting thrift server in python...")
server.serve()
print ("done!")

当客户端运行时,服务器经常出现错误BrokenPipeError: [Errno 32] Broken pipe,这似乎是线程问题。

那么如何修改代码?

1 个答案:

答案 0 :(得分:0)

通常的解决方案是在这种情况下关闭并重新打开运输工具。对于我到目前为止处理过的所有Thrift语言来说,这几乎都是正确的,因此对于Python也应如此。