如何将远程调试器附加到 Python 进程?
我厌倦了
import pdb; pdb.set_trace()
在 Python 程序中插入行并通过控制台进行调试。 如何连接远程调试器并从文明的用户界面插入断点?
I'm tired of inserting
import pdb; pdb.set_trace()
lines into my Python programs and debugging through the console. How do I connect a remote debugger and insert breakpoints from a civilized user interface?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 Winpdb。 它是一个独立于平台的图形化 GPL Python 调试器,支持通过网络进行远程调试、多线程、命名空间修改、嵌入式调试、加密通信,并且速度比 pdb 快 20 倍。
特点:
(来源:winpdb.org)
winpdb-reborn · PyPI
GitHub - bluebird75/winpdb:官方 winpdb 的分支并进行了改进
use Winpdb. It is a platform independent graphical GPL Python debugger with support for remote debugging over a network, multiple threads, namespace modification, embedded debugging, encrypted communication and is up to 20 times faster than pdb.
Features:
(source: winpdb.org)
winpdb-reborn · PyPI
GitHub - bluebird75/winpdb: Fork of the official winpdb with improvements
有点晚了,但这里有一个非常轻量级的远程调试解决方案,由
提供
Michael DeHaan • 使用 Ansible 调试器的技巧:
pip install epdb
。epdb
默认侦听任何地址 (INADDR_ANY
),而不是 127.0.0.1 。epdb.connect()
使用 telnet。当然,调整安全位以适合您的本地网络设置和安全立场。
A little bit late, but here is a very lightweight remote debugging solution courtesy of
Michael DeHaan • Tips on Using Debuggers With Ansible:
pip install epdb
on the remote host.epdb
defaults to listening on any address (INADDR_ANY
), not 127.0.0.1.import pdb; pdb.set_trace()
in your program, useimport epdb; epdb.serve()
.epdb.connect()
uses telnet.python -c 'import epdb; epdb.connect()'
.Adjust the security bits to suit your local network setup and security stance, of course.
嗯,你可以得到与使用扭曲的沙井非常相似的东西,这
工作原理如下:
然后你只需通过 ssh 登录到该程序;
使用foobar作为密码。
当你登录时,你会得到一个正常的 python 提示符,你可以在其中查看数据。
这与将回溯发送到主机不太一样。
现在,集成到 GUI 程序可能会很棘手,在这种情况下,您可能需要选择另一个反应器,例如基于 gtk 的程序使用 gtk2reactor 等。
如果您想要发送实际的回溯,您需要创建一个套接字通道对于 stderr、stdin 和 stdout,它们通过网络而不是打印到本地主机。 使用扭曲来完成应该不会太难。
Well, you can get something quite similar to that using a twisted manhole, which
works like this:
Then you just login to the program over ssh;
Using foobar as the password.
When you login you'll get a normal python prompt where you can just poke at the data.
It's not quite the same as getting a traceback sent over to a host.
Now, this might be tricky to integrate to a GUI program, in that case you might need to choose another reactor, for instance for gtk based programs used the gtk2reactor etc.
If you want the actual traceback sent over you need to create a socket channel for both stderr, stdin and stdout which goes over the network instead of printing to your local host. Shouldn't be too hard to accomplish by using twisted.
现代 IDE 的两种解决方案:
PTVS(适用于 Visual Studio 的 Python 工具)跨平台远程调试
PyCharm / PyDev远程调试
Two solutions from modern IDEs:
PTVS (Python tools for Visual Studio) cross-platform remote debugging
PyCharm / PyDev remote debugging
我发现 pudb 在紧急情况下很有用
项目描述
https://pypi.org/project/pudb/
教程:
https://vimeo.com/5255125
I find pudb useful at emergency
Project Description
https://pypi.org/project/pudb/
Tutorial:
https://vimeo.com/5255125
这里的答案都没有处理二进制文件未提前准备的情况。 为此,不久前我一起破解了 pydbattach。
一些解决方案:
None of the answers here handle the case where the binary was not prepared in advance. For that purpose, a while ago I hacked together pydbattach.
Some solutions: