I built a RPC server using Python 2.7 on Mac OS (AL Captian) by using the python Spyne wsgi application. The code is as follows:
hostname = "localhost"
port = 8000
application = Application([PybedictorService],
tns='spyne.examples.hello',
in_protocol=JsonDocument(validator='soft'),
out_protocol=JsonDocument()
)
try:
import argparse
parser = argparse.ArgumentParser(description='A simple fake server for testing your API client.')
parser.add_argument('-host', type=str, dest="host",
help='ip address of your server')
parser.add_argument("-port", type=int, dest="port",
help="specify which port you wanna run this server")
parser.add_argument("-mode", type=str, dest="mode",
help="json or html input")
args = parser.parse_args()
if args.host:
hostname = args.host
if args.port:
port = args.port
if args.mode == "html":
# spyne forbids decorated function inheritance from ServiceBase,
# instead, you have to use application composition
# by adding new inherited class into the new application expandable list.
application = Application([PybedictorServiceHtml, PybedictorService],
tns='spyne.examples.hello',
in_protocol=HttpRpc(validator='soft'),
out_protocol=JsonDocument()
)
except argparse.ArgumentError:
# Could not successfully import argparse or something
print "cannot successfully parse your input...."
pass
wsgi_app = WsgiApplication(application)
server = make_server(hostname, port, wsgi_app)
logging.info("RPC server is running at %s:%s" % (hostname, str(port)))
print "RPC server is running at %s:%s" % (hostname, str(port))
server.serve_forever()
And I also developed a function for this RPC_call to function. The GET POST is requested through html format. My client is trying to call via html format "http://localhost:8000/get_params?name=***&time=****". The client is calling very frequently. At the beginning it is working well, however, suddenly the roc_server stop to respond and the client gets Error: recv() failed (104: Connection reset by peer)
. I wonder why? I read some stack flow posts saying it is related to Python GIL which got a dead lock problem. After I restarted the RPC server, it starts to function again and after a while, the same problem came again. Can anybody know what is going on here?
Another hint here is that: My wsgi app might receive hundreds of parallel calls at the same time. Is that enough to trigger Python GIL to lock everything?