:first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { border: 0; max-width: 100%; height: auto !important; margin: 2px 0; } table { border-collapse: collapse; border: 1px solid #bbbbbb; } td, th { padding: 4px 8px; border-collapse: collapse; border: 1px solid #bbbbbb; } @media only screen and (-webkit-max-device-width: 1024px), only screen and (-o-max-device-width: 1024px), only screen and (max-device-width: 1024px), only screen and (-webkit-min-device-pixel-ratio: 3), only screen and (-o-min-device-pixel-ratio: 3), only screen and (min-device-pixel-ratio: 3) { html, body { font-size: 17px; } body { line-height: 1.7; padding: 0.75rem 0.9375rem; color: #353c47; } h1 { font-size: 2.125rem; } h2 { font-size: 1.875rem; } h3 { font-size: 1.625rem; } h4 { font-size: 1.375rem; } h5 { font-size: 1.125rem; } h6 { color: inherit; } ul, ol { padding-left: 2.5rem; } blockquote { padding: 0 0.9375rem; } }
-->

div{font-size:15px;}.wiz-table-tools .wiz-table-menu-item.active .wiz-table-menu-sub {display: block}.wiz-table-tools .wiz-table-menu-sub:before, .wiz-table-tools .wiz-table-menu-sub:after {position: absolute;content: " ";border-style: solid;border-color: transparent;border-bottom-color: #cccccc;left: 22px;margin-left: -14px;top: -8px;border-width: 0 8px 8px 8px;z-index:10;}.wiz-table-tools .wiz-table-menu-sub:after {border-bottom-color: #ffffff;top: -7px;}.wiz-table-tools .wiz-table-menu-sub-item {padding: 4px 12px;font-size: 14px;}.wiz-table-tools .wiz-table-menu-sub-item.split {border-top: 1px solid #E0E0E0;}.wiz-table-tools .wiz-table-menu-sub-item:hover {background-color: #ececec;}.wiz-table-tools .wiz-table-menu-sub-item.disabled {color: #bbbbbb;cursor: default;}.wiz-table-tools .wiz-table-menu-sub-item.disabled:hover {background-color: transparent;}.wiz-table-tools .wiz-table-menu-item.wiz-table-cell-bg:hover .wiz-table-color-pad {display: block;}.wiz-table-tools .wiz-table-color-pad {display: none;padding: 10px;box-sizing: border-box;width: 85px;height: 88px;background-color: #fff;cursor: default;}.wiz-table-tools .wiz-table-color-pad > div{font-size:15px;}.wiz-table-tools .wiz-table-color-pad .wiz-table-color-pad-item {display: inline-block;width: 15px;height: 15px;margin-right: 9px;position: relative;}.wiz-table-tools .wiz-table-color-pad .wiz-table-color-pad-item i.pad-demo {position: absolute;top:3px;left:0;}.wiz-table-tools .wiz-table-color-pad .wiz-table-color-pad-item .icon-oblique_line{color: #cc0000;}.wiz-table-tools .wiz-table-color-pad .wiz-table-color-pad-item:last-child {margin-right: 0;}.wiz-table-tools .wiz-table-color-pad .wiz-table-color-pad-item.active i.editor-icon.icon-box {color: #448aff;}.wiz-table-tools .wiz-table-cell-align {display: none;padding: 10px;box-sizing: border-box;width: 85px;height: 65px;background-color: #fff;cursor: default;}.wiz-table-tools .wiz-table-cell-align .wiz-table-cell-align-item {display: inline-block;width: 15px;height: 15px;margin-right: 9px;position: relative;}.wiz-table-tools .wiz-table-cell-align .wiz-table-cell-align-item:last-child {margin-right:0}.wiz-table-tools .wiz-table-cell-align .wiz-table-cell-align-item i.valign{position: absolute;top:3px;left:0;color: #d2d2d2;}.wiz-table-tools .wiz-table-cell-align-item.active i.editor-icon.valign {color: #a1c4ff;}.wiz-table-tools .wiz-table-cell-align-item.active i.editor-icon.icon-box,.wiz-table-tools .wiz-table-cell-align-item.active i.editor-icon.align {color: #448aff;}.wiz-table-tools .wiz-table-color-pad .wiz-table-color-pad-item:last-child,.wiz-table-tools .wiz-table-cell-align .wiz-table-cell-align-item:last-child {margin-right: 0;}th.wiz-selected-cell-multi, td.wiz-selected-cell-multi {background: rgba(0,102,255,.05);}th:before,td:before,#wiz-table-col-line:before,#wiz-table-range-border_start_right:before,#wiz-table-range-border_range_right:before{content: " ";position: absolute;top: 0;bottom: 0;right: -5px;width: 9px;cursor: col-resize;background: transparent;z-index:100;}th:after,td:after,#wiz-table-row-line:before,#wiz-table-range-border_start_bottom:before,#wiz-table-range-border_range_bottom:before{content: " ";position: absolute;left: 0;right: 0;bottom: -5px;height: 9px;cursor: row-resize;background: transparent;z-index:100;}.wiz-table-container {}.wiz-table-body {position:relative;padding:0 0 10px;overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch;}.wiz-table-body table {margin:0;outline:none;}td,th {height:28px;word-break:break-all;box-sizing:border-box;outline:none;}body pre.prettyprint {padding:0;}body pre.prettyprint code {white-space: pre;}body pre.prettyprint.linenums {box-shadow:none; overflow: auto;-webkit-overflow-scrolling: touch;}body pre.prettyprint.linenums ol.linenums {box-shadow: 40px 0 0 #FBFBFC inset, 41px 0 0 #ECECF0 inset; padding: 10px 10px 10px 40px !important;}
-->

Flask 出现 "Broken pipe" 现象说明:
采用 Flask 原生 WSGI 发布 Web(app.run())。随后,发起一个 Request,在 Request 还未返回前停止查询,并重新发起一个新的 Request。服务端很可能出现类似如下的"Broken pipe"报错。
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usrb64/python2.7/threading.py", line 811, in __bootstrap_inner
    self.run()
  File "/usrb64/python2.7/threading.py", line 764, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usrb/python2.7/site-packages/werkzeugrving.py", line 659, in inner
    srv.serve_forever()
  File "/usrb/python2.7/site-packages/werkzeugrving.py", line 499, in serve_forever
    HTTPServer.serve_forever(self)
  File "/usrb64/python2.7/SocketServer.py", line 238, in serve_forever
    self._handle_request_noblock()
  File "/usrb64/python2.7/SocketServer.py", line 297, in _handle_request_noblock
    self.handle_error(request, client_address)
  File "/usrb64/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usrb64/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usrb64/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usrb64/python2.7/SocketServer.py", line 649, in __init__
    self.handle()
  File "/usrb/python2.7/site-packages/werkzeugrving.py", line 216, in handle
    rv = BaseHTTPRequestHandler.handle(self)
  File "/usrb64/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usrb/python2.7/site-packages/werkzeugrving.py", line 251, in handle_one_request
    return self.run_wsgi()
  File "/usrb/python2.7/site-packages/werkzeugrving.py", line 193, in run_wsgi
    execute(self.server.app)
  File "/usrb/python2.7/site-packages/werkzeugrving.py", line 184, in execute
    write(data)
  File "/usrb/python2.7/site-packages/werkzeugrving.py", line 152, in write
    self.send_header(key, value)
  File "/usrb64/python2.7/BaseHTTPServer.py", line 401, in send_header
    self.wfile.write("%s: %s\r\n" % (keyword, value))
IOError: [Errno 32] Broken pipe
 

"Broken pipe" 报错原因:<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

 
 
 
 
"Broken pipe" 的字面意思为 "管道破裂",本质为写入端反馈时读端却关闭,因而造成没有及时取走管道中的数据,从而引发程序异常。
 
"Broken pipe" 报错处理方式:
放弃对 Flask 原生 WSGI 的使用,转而使用全功能的 WSGI,例如:gunicorn、uWSGI 等。
 
多种 WSGI 对引发 "Broken pip" 报错操作的响应对比:
1.Flask 原生 WSGI
采用 Flask 原生 WSGI 的最简测试程序如下。
from flask import Flask
                                                                          
app = Flask(__name__)
                                                                             
@app.route('/')
def index():
    import time
    time.sleep(10)
    return 'Hello World'
                                   
app.run(host='11.4.76.73', port=6001)
调用方式如下。
# ./env/bin/python flasktest.py
当发起一个 Request,在 Request 还未返回前停止查询,并重新发起一个新的 Request时,WSGI 响应类似如下。

注意:报错"Broken pipe",程序崩溃
2.gunicorn
采用 gunicorn 的最简测试程序如下。
from flask import Flask
                                     
app = Flask(__name__)
                                       
@app.route('/')
def index():
    import time
    time.sleep(10)
    return 'Hello World'
调用方式如下。
# ./env/bin/gunicorn -w 1 --log-level 'debug' -b 11.4.76.73:6002 gunicorntest:app
当发起一个 Request,在 Request 还未返回前停止查询,并重新发起一个新的 Request时,WSGI 响应类似如下。

注意:出现"Ignoring connection reset"信息,但不影响应用运行。
3.pywsgi
采用 pywsgi 的最简测试程序如下。
from gevent import monkey
monkey.patch_all()
from flask import Flask
from gevent import pywsgi
                                       
app = Flask(__name__)
                                       
@app.route('/')
def index():
    import time
    time.sleep(10)
    return 'Hello World'
                                   
server = pywsgi.WSGIServer(('11.4.76.73', 6003), app)
server.serve_forever()
调用方式如下。
# ./env/bin/python geventtest.py
当发起一个 Request,在 Request 还未返回前停止查询,并重新发起一个新的 Request时,WSGI 响应类似如下。
注意:应用正常。

因采用 Flask 原生 WSGI 出现 "Broken pipe" 报错的故障处理的更多相关文章

  1. broken pipe 报错分析和解决办法

    参考资料: 1.博客1:https://blog.csdn.net/qq_37535749/article/details/113781338 2.博客2:https://blog.csdn.net/ ...

  2. flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法

    flask+sqlite3+echarts2+ajax数据可视化报错: UnicodeDecodeError: 'utf8' codec can't decode byte 解决方法: 将 py文件和 ...

  3. flask笔记(三)Flask 添加登陆验证装饰器报错,及解析

    Flask 添加登陆验证装饰器报错,及解析 写这个之前,是想到一个需求,这个是关于之前写Flask笔记(二)中的一个知识点,路由相关 需求为 : 有一些页面必须是登陆之后才能访问的,比如Shoppin ...

  4. Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.

    背景 有一个 Flask 项目,然后有一个路由返回的是 dict 通过浏览器访问,结果报错 关键报错信息 TypeError: 'dict' object is not callable The vi ...

  5. from flask.ext.wtf import Form导入报错

    问题来源: 在学习Flask网上教程(PS:中文版教程链接,英文版教程其中代码是对的,运行没错误,我为了看的快一些,所以就直接看的中文版>~<,英文版教程链接)时,使用如下代码: from ...

  6. Python直接改变实例化对象的列表属性的值 导致在flask中接口多次请求报错

    错误原理实例如下: class One(): list = [1, 2, 3] @classmethod def get_copy_list(cls): # copy一份list,这样对list的改变 ...

  7. 解决thinkphp query()执行原生SQL语句成功结果报错的问题

    1.query方法 query方法用于执行SQL查询操作,如果数据非法或者查询错误则返回false,否则返回查询结果数据集(同select方法). 2.execute方法 execute用于更新和写入 ...

  8. 采用WebService客户端调用WSDL/SOAP网络报错的解决办法

    WebService接口是网络传输控制的重要途径,在Windows系统下运行客户端时,平时一直能正确运行,但某天可能突然会发生调用wsdl soap邮件标头无法识别等莫名其妙的错误提示,出现这种情况一 ...

  9. 首次接触flask遇到socket.error: [Errno 10013] 报错

    解决方案: 发现是因为端口5000被占用了,设置一个其他port就行:app.run(port=5050)

随机推荐

  1. MyEclipse Tern was unable to complete your request in time

    1.错误描述 2.错误原因 由错误提示可知,是由于MyEclipse Tern不能及时完成回复 3.解决办法 (1)Window--->Preferences--->MyEclipse-- ...

  2. 4.CRT远程连接的使用

    目录: 1.为什么需要远程连接? 2.一般的远程连接工具有哪些? 3.远程连接的原理? 4.远程连接的软件的功能和使用相关技巧? 1.为什么选择远程连接? 因为在实际工作中,机房一般都不可能在办公室, ...

  3. golang包快速生成base64验证码

    base64Captcha快速生成base64编码图片验证码字符串 支持多种样式,算术,数字,字母,混合模式,语音模式. Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一.Base6 ...

  4. input光标位置不居中问题

    文本输入框默认在谷歌,火狐浏览器中,光标是居中显示的.但在IE7中一开始会在顶部闪烁(输入文字后光标居中),加上行高就可以,值为文本框的高度. 注意要加*号,否则在谷歌浏览其中光标会在顶部闪烁. *l ...

  5. HDFS的工作原理扫扫盲

    问题导读: 1.什么是分布式文件系统? 2.怎样分离元数据和数据? 3.HDFS的原理是什么? Hadoop分布式文件系统(HDFS)是一种被设计成适合运行在通用硬件上的分布式文件系统.HDFS是一个 ...

  6. vc++ windows获取计算机信息

    在软件开发中,我们经常要获当前系统的版本号,判断当前是什么系统,获取获取物理内存和可用内存大小,获取CPU名称.内核数目.主频,获取MAC地址,获取屏幕分辨率,下面的这个c++类将包含所有这些信息. ...

  7. struts1和struts2原理解析

    1.struts1和struts2 是2个完全不同的框架 其实struts2核心就是 webwork框架 struts1以ActionServlet作为核心控制器,由ActionServlet负责拦截 ...

  8. Android中Activity的LauchMode(加载模式)

    1.standard模式:一个task有多个Activity,一个Activity可以被实例化多次,可以放在不同的task中. 2.singleTop模式:该Activity在栈顶,同时收到启动该Ac ...

  9. 十、python沉淀之路--高阶函数初识

    一.高阶函数:分两种:一种是返回值中包含函数体:另一种是把一个函数体当作了参数传给了另一个函数 1.返回值中包含函数体 例1. def test(): print('这是一个测试') return t ...

  10. Hadoop(二)自定义输出

    Hadoop提供了较为丰富的数据输入输出格式,可以满足很多的设计实现,但是在某些时候需要自定义输入输出格式. 数据的输入格式用于描述MapReduce作业的数据输入规范,MapReduce框架依靠 数 ...