Spyne RPC服务器recv()失败(104:由对等方重置连接)

时间:2016-10-14 00:22:07

标签: python python-2.7 rpc spyne

我使用python Spyne wsgi应用程序在Mac OS(AL Captian)上使用Python 2.7构建了一个RPC服务器。代码如下:

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()

我还为此RPC_call开发了一个函数。通过html格式请求GET POST。我的客户正试图通过html格式调用" http://localhost:8000/get_params?name= ***& time = ****"。客户经常打电话。一开始它运行良好,然而,突然roc_server停止响应,客户端获得Error: recv() failed (104: Connection reset by peer)。我想知道为什么?我读了一些堆栈流帖,说它与Python GIL有关,它有一个死锁问题。重新启动RPC服务器后,它再次开始运行,一段时间后,再次出现同样的问题。谁能知道这里发生了什么?

这里的另一个暗示是:我的wsgi应用程序可能会同时收到数百个并行调用。这足以触发Python GIL锁定一切吗?

0 个答案:

没有答案