Python使用Bottle框架的Paste出现Broken Pipe错误

5

我正在使用Bottle框架实现WSGI请求和响应,但由于单线程问题,我将服务器更改为PythonWSGIServer,并使用Apache bench进行测试,但结果包含错误的断开管道,与此问题类似如何防止errno 32 broken pipe。 我尝试了该答案,但无效。

  Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/paste/httpserver.py", line 1068, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 641, in __init__
    self.finish()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

以下是服务器端的代码,我不知道如何改进连接,是否可以使用线程池?
from paste import httpserver

    @route('/')
    def index():
        connection = pymongo.MongoClient(connectionString)
        db = connection.test
        collection = db.test
        return str(collection.find_one())

    application = default_app()
    httpserver.serve(application, host='127.0.0.1', port=8082)
1个回答

3

问题是由于WSGIServer是一个同步服务器,不适用于同时发送高并发用户请求的情况。为了避开这些问题,可以使用许多第三方框架。其中流行的有Gevent greenlet libraries、Tornado和CherryPy。它们都基于事件驱动和异步方法论,使它们能够处理多个并发用户。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接