我已经设置了一个基本的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
,就能够运行该应用程序,我需要能够对该应用程序进行调试。有人知道这是怎么回事吗?