我只想停止/关闭使用python创建的节俭TSimpleServer。但是,由于错误“ AttributeError:'TSimpleServer'对象没有属性'stop',所以没有.stop()和.close()可以执行此操作。”有什么解决方案可以解决这个问题吗?任何帮助将不胜感激。
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from rpc1_nodejs_call_python import printService
from TestHandler import TestHandler
processor = printService.Processor(TestHandler())
transport = TSocket.TServerSocket(host='127.0.0.1', port=8080)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
print("Starting thrift server in python...")
server.serve()
print("Stoping thrift server in python...")
server.stop()
# server.close()
答案 0 :(得分:2)
实际上,似乎根本不可能/无法预见: https://github.com/apache/thrift/blob/master/lib/py/src/server/TServer.py
正如您所注意到的,没有stop()
,并且所有三个服务器实现当前都在不断循环while true
。
假定有人将要添加的通常方法是使用stop()
方法,该方法设置一些标志等来指示终止。必须从另一个线程进行调用,因为服务时第一个线程仍保留在serve()
内。
底线:似乎尚未实现。