Python Paste 使用 Bottle 框架 Broken Pipe Error

标签 python paste

我正在使用实现 WSGI 请求和响应的 Bottle 框架,并且由于单线程问题,我将服务器更改为 PythonWSGIServer 并使用 Apache bench 进行了测试,但结果包括与此问题类似的 error broken pipe How to prevent 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)

最佳答案

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

关于Python Paste 使用 Bottle 框架 Broken Pipe Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15736685/

相关文章:

excel - 复制粘贴图表 Excel VBA

在代码中将 Cocoa Paste 到 NSTextView

python - 在 Windows 操作系统上通过 Waitress 猎鹰

python - 将 Pandas 数据框中的字符串转换为列表的最佳方法是什么?

python - 在 node-webkit 启动时运行 python 脚本 (nw.js)

python - 无法将字符串转换为 float

ckeditor - CKeditor 中的粘贴选项在 Chrome 和 firefox 中似乎不起作用

python - 如何在多个进程之间共享缓存?

javascript - TinyMCE 粘贴按钮仅适用于 Internet Explorer

excel - 为什么我收到 'type mismatch' 错误?