Run pdb without stdin/stdout using FIFO

岁酱吖の 提交于 2019-11-30 21:42:41

Ok. Exactly what I want, has been done in http://pypi.python.org/pypi/rpdb/0.1.1 .

Before starting the python app

mkfifo pdb.in
mkfifo pdb.out

Then when pdb is called you can interact with it using these two cat commands, one running in the background

cat pdb.out & cat > pdb.in

Note the readline support does not work (i.e. up arrow)

I just ran into a similar issue in a much simpler use-case:

  • debug a simple Python program running from the command line that had a file piped into sys.stdin, meaning, no way to use the console for pdb.

I ended up solving it by using wdb.

Quick rundown for my use-case. In the shell, install both the wdb server and the wdb client:

pip install wdb.server wdb

Now launch the wdb server with:

wdb.server.py

Now you can navigate to localhost:1984 with your browser and see an interface listing all Python programs running. The wdb project page above has instructions on what you can do if you want to debug any of these running programs.

As for a program under your control, you can you can debug it from the start with:

wdb myscript.py --script=args < and/stdin/redirection

Or, in your code, you can do:

import wdb; wdb.set_trace()

This will pop up an interface in your browser (if local) showing the traced program.

Or you can navigate to the wdb.server.py port to see all ongoing debugging sessions on top of the list of running Python programs, which you can then use to access the specific debugging session you want.

Notice that the commands for navigating the code during the trace are different from the standard pdb ones, for example, to step into a function you use .s instead of s and to step over use .n instead of n. See the wdb README in the link above for details.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!