gevent.hub.LoopExit: ('This operation would block forever',

使用pycharm运行flask的monkey patch(猴子补丁)时,调试和运行代码报错:

Exception happened during processing of request from ('127.0.0.1', 53647)
Traceback (most recent call last):
  File "C:\Python36\lib\socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Python36\lib\socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python36\lib\socketserver.py", line 696, in __init__
    self.handle()
  File "C:\Python36\lib\site-packages\werkzeug\serving.py", line 325, in handle
    rv = BaseHTTPRequestHandler.handle(self)
  File "C:\Python36\lib\http\server.py", line 418, in handle
    self.handle_one_request()
  File "C:\Python36\lib\site-packages\werkzeug\serving.py", line 356, in handle_one_request
    self.raw_requestline = self.rfile.readline()
  File "C:\Python36\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "C:\Python36\lib\site-packages\gevent\_socket3.py", line 384, in recv_into
    self._wait(self._read_event)
  File "C:\Python36\lib\site-packages\gevent\_socket3.py", line 156, in _wait
    self.hub.wait(watcher)
  File "C:\Python36\lib\site-packages\gevent\hub.py", line 651, in wait
    result = waiter.get()
  File "C:\Python36\lib\site-packages\gevent\hub.py", line 898, in get
    return self.hub.switch()
  File "C:\Python36\lib\site-packages\gevent\hub.py", line 630, in switch
    return RawGreenlet.switch(self)
gevent.hub.LoopExit: ('This operation would block forever', <Hub at 0x3cc6178 select pending=0 ref=0>)
----------------------------------------

 

代码实例:

from flask import Flask
from gevent import monkey
from gevent import pywsgi
import pymysql

monkey.patch_all(thread=False)  # 使用猴子补丁,将真个应用转变为协程的方式运行,提高并发性能,thread=False使多线程不阻塞
app = Flask(__name__)

@app.route('/t')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    #app.run()
    server = pywsgi.WSGIServer(("127.0.0.1", 5000), app)  # 使用WSGIServer将app应用封装成wsgi服务
    server.serve_forever()

原因分析:

查看代码没有配置和编辑错误

查看flask启动命令打印:

C:\Python36\python.exe -m flask run
 * Serving Flask app "main.py"
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

发现启动的命令不对

根因分析:

配置运行的命令不对,这是默认flask启动的配置

解决方式:

修改flask启动环境及命令配置

如上为正常启动右键格式,打印的执行命令应该如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值