gpt4 book ai didi

python-3.x - bdb.BdbQuit 在 uwsgi 服务器上运行的 Flask 应用程序中使用 pdb 时引发

转载 作者:行者123 更新时间:2023-12-03 16:04:48 26 4
gpt4 key购买 nike

我正在使用 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

有什么方法可以让pdbgevent下运行时正常工作?

最佳答案

深入研究后我意识到你不应该使用

from gevent.pywsgi import WSGIServer
application = WSGIServer((application.config.SERVER_HOST, application.config.SERVER_PORT), application)

因为它不起作用。所以你可以使用旧的 wsgi.py 版本。现在问题出现了,因为当你是 uwsgi 时,没有 stdin 并且它指向 /dev/null。由于没有标准输入,调试器无法启动。看下面的线程

How to debug python application under uWSGI?

所以你想要的是在运行 uwsgi 时添加 --hounor-stdin--gevent

uwsgi --http 0.0.0.0:5000 \
--gevent 10 \
--http-websockets \
--master \
--wsgi-file automoticz/wsgi.py \
--honour-stdin

现在可以调试了

Debugging working

关于python-3.x - bdb.BdbQuit 在 uwsgi 服务器上运行的 Flask 应用程序中使用 pdb 时引发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56656254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com