"Advanced articles" Python Development Information Service of docker (11)
Original articles, welcome to reprint. Reprint please indicate: reproduced from IT Story Association, thank you!
Original link address: "Advanced articles" Python Development Information Service of docker (11)
The information service is ready to be written in python, adding python modules to the existing idea. Source code: https://github.com/limingios/msA-docker
Idea installs the python plug-in
Re-idea after installation.
Install the python module
Install the pyhon plug-in for thrift
At first, I used idea to write python, and it was hard to download a plug-in. I replaced it with pycharm to write about Meizi.
Edit Python's service code # coding: utf-8from message.api import MessageServicefrom thrift.transport import TSocketfrom thrift.transport import TTransportfrom thrift.protocol import TBinaryProtocolfrom thrift.server import TServerclass MessageServiceHandler: def sendMobileMessage (self, mobile, message): print ("sendMobileMessage, mobile:" + mobile+ ", message:" + message) return True def sendEmailMessage (self, email, message): print ("sendEmailMessage, email:" + email+ " Message: "+ message) return Trueif _ _ name__ ='_ _ main__': handler = MessageServiceHandler () processor = MessageService.Processor (handler) transport = TSocket.TServerSocket (None," 9090 ") tfactory = TTransport.TFramedTransportFactory () pfactory = TBinaryProtocol.TBinaryProtocolFactory () server = TServer.TSimpleServer (processor, transport, tfactory, pfactory) print (" python thrift server start ") server.serve () print (" python thrift server exit ")
Check that the port has been started
Generate commands corresponding to java and python
The corresponding superior directory is generated according to the thrift file.
Thrift-- gen py-out.. / message.thriftthrift-- gen java-out.. / message.thrift
The development process of PS:thrift is to define the file of thrift first, and then generate the corresponding python code by command. The call to thrift is completed by implementing the defined thrift method.