Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在uWSGI下调试python应用程序?_Python_Uwsgi - Fatal编程技术网

如何在uWSGI下调试python应用程序?

如何在uWSGI下调试python应用程序?,python,uwsgi,Python,Uwsgi,当我尝试在uWSGI下使用python pdb调试器时,执行不会在断点处停止,它只返回trackback 代码如下: def application(env, start_response): import pdb; pdb.set_trace() start_response('200 OK', [('Content-Type','text/html')]) return "Hello World" 我是这样运行它的: uwsgi --http 127.0.0.1:7

当我尝试在uWSGI下使用python pdb调试器时,执行不会在断点处停止,它只返回trackback

代码如下:

def application(env, start_response):
    import pdb; pdb.set_trace()
    start_response('200 OK', [('Content-Type','text/html')])
    return "Hello World"
我是这样运行它的:

uwsgi --http 127.0.0.1:7777  --wsgi-file uwsgi_test.py
这就是我得到的:

/home/andrey/Development/ttt/uwsgi_test.py(3)application()
-> start_response('200 OK', [('Content-Type','text/html')])
(Pdb) 
Traceback (most recent call last):
  File "uwsgi_test.py", line 3, in application
    start_response('200 OK', [('Content-Type','text/html')])
  File "uwsgi_test.py", line 3, in application
    start_response('200 OK', [('Content-Type','text/html')])
  File "/usr/lib/python2.7/bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python2.7/bdb.py", line 67, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
[pid: 11421|app: 0|req: 1/1] 127.0.0.1 () {32 vars in 366 bytes} [Sun Aug 25 13:12:06 2013] GET / => generated 0 bytes in 63 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

作为服务器,uWSGI关闭stdin(实际上它将其重新映射到/dev/null)

如果需要stdin(就像需要终端调试器一样),请添加:

试试这个

uwsgi --http 127.0.0.1:7777  --wsgi-file uwsgi_test.py --logto /path/to/log/log.txt

安装远程调试器

pip install remote-pdb
在应用程序中的某个位置设置断点

from remote_pdb import RemotePdb
RemotePdb('127.0.0.1', 4444).set_trace()
通过telnet连接到远程调试器

# Restart uwsgi to pick up changes
...

# Trigger the breakpoint, (any action to evaluate the set_trace call)
...

# Connect to debugger
telnet 127.0.0.1 4444

您可能希望使用单个工作线程/线程运行uWSGI,这样远程调试器就不会相互干扰。

您是否尝试过以不同的方式调试它(即,而不是使用
set\u trace()
手动插入断点)?我正在简单的文本编辑器中开发它,没有任何IDE。所以我知道的唯一选择是断点。看看这篇文章:除了一个好的IDE真的可以让你的生活更轻松(并有助于提高生产力等)。这是不用说的,但万一其他人没有意识到这一点,你还需要确保你没有在守护程序模式下运行uwsgi。否则,您必须在事后将终端连接到进程的stdin/stdout(这可能吗?)@DavidSanders在没有守护程序模式的情况下如何运行uwsgi?
uwsgi--http socket:8000--wsgi文件uwsgi_test.py--callable application--virtualenv/opt/virtualenvs/uwsgi_test--honor stdin
为meCan add
--workers 1
工作,所以您只需要担心一个worker,还有,
--harakiri 1200
给你20分钟的调试时间,否则它可能会在60秒后重新出现。这不是调试,甚至没有给出一个合适的python stacktraceIt,它没有回答这个问题,但是这个评论对我很有帮助。
# Restart uwsgi to pick up changes
...

# Trigger the breakpoint, (any action to evaluate the set_trace call)
...

# Connect to debugger
telnet 127.0.0.1 4444