由于pos原因,调试时UWSGI未运行flask应用程序

2024-06-26 14:15:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安装了一个基本的Flask应用程序,它使用pydevd来远程调试python应用程序。我们还使用了uwsgidecorators的postfork()方法。代码看起来像这样

from flask import Flask

import sys
sys.path.append('pycharm-debug.egg')  # replace by pycharm-debug.egg for Python 2.7
import pydevd
# the following line can be copied from "Run/Debug Configurations" dialog
pydevd.settrace('localhost', port=4444, stdoutToServer=True, stderrToServer=True)


print __name__

application = Flask(__name__)


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


def initialize():
    print "This is called"


try:
    from uwsgidecorators import postfork
    postfork(initialize)
except ImportError:
    pass


if __name__ == '__main__':
    application.run(host='0.0.0.0', port=8055)

那个网址:uWSGI.ini文件看起来像这样

[uwsgi]
module = app
socket = 0.0.0.0:8000
master = true

现在,当我尝试运行uwsgi ./uwsgi.ini时,调试器确实在第一行中断,即在print __name__上,但应用程序没有启动。需要注意的一点是postfork()不调用intialize方法。经过一些尝试和错误,如果我删除了pydev.settrace,我就可以运行应用程序了,我需要能够调试应用程序。有人知道这是怎么回事吗?你知道吗


Tags: 方法namefromdebugimport应用程序flaskapplication