当我尝试在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"
Run Code Online (Sandbox Code Playgroud)
这是我运行它的方式:
uwsgi --http 127.0.0.1:7777 --wsgi-file uwsgi_test.py
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
/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)
Run Code Online (Sandbox Code Playgroud)
rob*_*rto 67
作为服务器,uWSGI关闭stdin(实际上它将其重新映射到/ dev/null).
如果你需要stdin(当你需要一个终端调试器时)添加:
--honour-stdin
Run Code Online (Sandbox Code Playgroud)
cdo*_*orn 15
安装远程调试器.
pip install remote-pdb
Run Code Online (Sandbox Code Playgroud)
在应用程序的某处设置断点.
from remote_pdb import RemotePdb
RemotePdb('127.0.0.1', 4444).set_trace()
Run Code Online (Sandbox Code Playgroud)
通过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
Run Code Online (Sandbox Code Playgroud)
您可能希望使用单个工作程序/线程运行uWSGI,以便远程调试器不会相互踩踏.