使用 Bottle 框架的 Python Paste Broken Pipe 错误 [英] Python Paste using Bottle framework Broken Pipe Error

查看:66
本文介绍了使用 Bottle 框架的 Python Paste Broken Pipe 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Bottle 框架来实现 WSGI 请求和响应,并且由于单线程问题,我将服务器更改为 PythonWSGIServer 并使用 Apache bench 进行测试,但结果包括错误损坏的管道,与此问题类似 如何防止 errno 32 断管?.我已经尝试了答案,但无济于事.

I am using Bottle framework implementing the WSGI Request and response and because of the single thread issue, I changed the server into PythonWSGIServer and tested with Apache bench but the result consist of error broken pipe which is similar with this question How to prevent errno 32 broken pipe?. I have tried the answer but to no avail.

  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

服务端代码如下所示,不知道如何改善连接,使用线程池?

The server code is shown below, and I have no idea how to improve the connection, using thread pool?

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.它们都基于事件驱动和异步方法,使它们能够处理多个并发用户.

The problem is due to WSGIServer is a synchronous server, and it is not applicable for high concurrent users sending requests at the same time. In order to bypass these fallbacks, there are a lot of third-party frameworks can be used. Popular among them are Gevent greenlet libraries, Tornado, and CherryPy. All of them are based on Event-driven and asynchronous methodologies, enabling them to handle multiple concurrent users.

这篇关于使用 Bottle 框架的 Python Paste Broken Pipe 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆