0

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?

Gauss Lee
  • 93
  • 10
  • Try with another wsgi implementation, this doesn't seem to be a Spyne issue. – Burak Arslan Oct 14 '16 at 11:24
  • @BurakArslan Why do you say it is not a spyne issue? Another wsgi? which one do you mean particularly? – Gauss Lee Oct 14 '16 at 11:27
  • Spyne doesn't contain any wsgi implementation. Nowhere in its code is `recv()` or family is called. It's the job of the libraries and frameworks that Spyne integrates with. I'm quite happy with Twisted's WSGI support. CherryPy seems to work great for others. – Burak Arslan Oct 15 '16 at 20:32
  • @BurakArslan Isn't `wsgi_app = WsgiApplication(application)` a WSGI causing this problem? I searched in the stack overflow, there are some other people pointing out that python GIL might cause this problem if the client side calls too frequently. I am not so familiar with wsgi application. any client side requirement if a wsgi application is created? It is just a simple GET POST html call. – Gauss Lee Oct 16 '16 at 22:22
  • I know a thing or two about how WSGI works and again: no Spyne code is responsible for this error. – Burak Arslan Oct 18 '16 at 07:32

0 Answers0