python-3.x - bdb.BdbQuit 在 uwsgi 服务器上运行的 Flask 应用程序中使用 pdb 时引发
问题描述
我在我的项目中使用Flask-SocketIO库。因为 websockets 需要与主 Flask 应用程序“并行运行”,所以我需要使用gevent-websocket库。当我尝试在create_app
方法中为调试器设置断点时会出现问题:
我的app.py
文件:
# monkey patching standard library before importing
# other modules
from gevent import monkey
monkey.patch_all()
import os
import logging.config
from flask import Flask
from dynaconf import FlaskDynaconf
...
# other imports
def configure_app(app):
'''
Configure app settings.
'''
FlaskDynaconf(app)
import pdb; pdb.set_trace()
logging.config.fileConfig(app.config.LOGGING_SETTINGS)
...
def create_app(run_from_celery=False):
'''
Create new Flask app instance.
'''
app = Flask('automoticz')
configure_app(app)
# ...
return app
当我启动服务器(我正在使用uwsgi)时,我收到以下错误:
$ uwsgi --http 0.0.0.0:5000 \
--gevent 1000 \
--http-websockets \
--master \
--wsgi-file automoticz/wsgi.py \
--callable app
Traceback (most recent call last):
File "automoticz/wsgi.py", line 3, in <module>
app = create_app()
File "./automoticz/app.py", line 138, in create_app
configure_app(app)
File "./automoticz/app.py", line 28, in configure_app
logging.config.fileConfig(app.config.LOGGING_SETTINGS)
File "./automoticz/app.py", line 28, in configure_app
logging.config.fileConfig(app.config.LOGGING_SETTINGS)
File "/usr/lib/python3.5/bdb.py", line 48, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python3.5/bdb.py", line 67, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 22694)
spawned uWSGI worker 1 (pid: 22702, cores: 1000)
spawned uWSGI http 1 (pid: 22703)
*** running gevent loop engine [addr:0x494fa0] ***
我尝试使用gevent-tools中的已修补 pdb,但结果相同import gtools.pdb; gtools.pdb.set_trace()
104 @app.before_request
105 def log_request_info():
106 import gtools.pdb
107 gtools.pdb.set_trace()
108 -> log_request(request)
(Pdb++)
2019-07-14 19:52:30 - flask.app - ERROR - Exception on /api/system/ws_devices [GET]
Traceback (most recent call last):
File "./automoticz/app.py", line 108, in log_request_info
log_request(request)
File "./automoticz/app.py", line 108, in log_request_info
log_request(request)
File "/usr/lib/python3.5/bdb.py", line 48, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python3.5/bdb.py", line 67, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
pdb
在下运行时有什么方法可以正常工作gevent
吗?
解决方案
挖掘了一下后,我意识到你不应该使用
from gevent.pywsgi import WSGIServer
application = WSGIServer((application.config.SERVER_HOST, application.config.SERVER_PORT), application)
因为它不起作用。因此,您可以使用旧wsgi.py
版本。现在问题出现了,因为当你在uwsgi
那里时stdin
,它被指向了/dev/null
。由于没有标准输入,调试器无法启动。请参阅下面的线程
所以你想要的是在运行时添加--hounor-stdin
and--gevent
uwsgi
uwsgi --http 0.0.0.0:5000 \
--gevent 10 \
--http-websockets \
--master \
--wsgi-file automoticz/wsgi.py \
--honour-stdin
现在调试工作
推荐阅读
- c - MinGW CMake make googletest 出现错误但没有命中
- php - 网关超时 webfoersterei / domain-bestellsystem-api-client
- git - git 正在向我的命令字符串添加控制字符,因此会炸毁 '$'\033''[m'
- angular - 自定义样式不适用于 angular 10
- javascript - 我将如何获得一个现有的按钮来使用 html 更改对象的不透明度?
- image - 电子名片照片未出现在联系人中
- firebase - 如何从 Firbase 数据库中获取特定数据
- mysql - mysql,当我向选择中添加一列时,结果会有所不同
- sql - Grafana 更改 SQL 查询以汇总每个数据点
- liquid - 乘以字符串格式的合并标签