I just would like to stop/close a thrift TSimpleServer created with python. However, no .stop() and .close() can do this due to the error "AttributeError: 'TSimpleServer' object has no attribute 'stop'." Is there any solution can solve this? Any help would be greatly appreciated.
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()
Actually it seems not possible/foreseen at all: https://github.com/apache/thrift/blob/master/lib/py/src/server/TServer.py
As you noticed, there is no stop()
and all three servers implementations currently loop endlessly while true
.
The usual approach, assumed someone would be going to add this, would be to have a stop()
method which sets some flag or the like to indicate termination. The call to it must be made from another thread, since the first one is still kept inside serve()
while serving.
Bottom line: Seems not implemented yet.