有没有办法调试在“multiprocessing.Process”上运行的Python代码?
我希望能够使用 multiprocessing
包对在单独进程中运行的代码进行单步调试。
我记得大约一年前寻找解决方案但没有找到。有人告诉我只需进行大量日志记录,但这当然是一种较差的方法。那么也许有人同时想出了一个解决方案?例如,某种使新生成的进程与调试器连接的机制?
What I would like is to be able to step-debug code that runs in a separate process using the multiprocessing
package.
I remember looking for a solution about a year ago and not finding one. I was told to just do a lot of logging, but of course it is an inferior method. So maybe someone came up with a solution in the meantime? For example, some mechanism for making the newly-spawned process connect with the debugger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以手动启动需要调试的进程,而无需在此进程上使用 Process 接口。
You could start the process You need to debug manually, without using the Process interface on this process.
您可能会发现 WingIDE 很有用。它的调试器非常好,它甚至支持通过对正在调试的代码进行一些最小的检测来调试远程进程。它不是免费的,但非常值得,恕我直言。 (我与 Wingware 没有任何关系,只是一个满意的客户...)
要在 Wing 中启用远程调试,您需要将文件
wingdbstub.py
复制到与应用程序相同的目录您想要调试,然后将其导入到代码中您想要开始调试的位置。 (WingIDE 文档对此进行了相当详尽的介绍。)如果您以这个例子< /a> 并将
myfunc()
方法修改为如下所示:您应该能够启动 WingIDE,在
import
行之后立即设置断点,然后启动示例来自控制台的脚本。它应该自动连接到 Wing 并在断点处停止。如果您在调试连接时遇到任何问题,您可能会发现这篇文章很有帮助工作。 (WingIDE 文档在解决连接问题方面也做得不错。)
You might find WingIDE useful. Its debugger is really nice, and it even supports debugging remote processes with some minimal instrumentation to the code being debugged. It's not free, but well worth the cost, IMHO. (I'm not affiliated with Wingware in any way, just a satisfied customer...)
To enable remote debugging in Wing, you need to copy the file
wingdbstub.py
to the same directory as the app you want to debug, and import it at the spot in your code you want debugging to begin. (This is covered fairly thoroughly in the WingIDE docs.)If you take this example and modify the
myfunc()
method to look as follows:you should be able to launch WingIDE, set a breakpoint immediately after the
import
line, then launch the example script from a console. It should automatically connect to Wing and stop at your breakpoint.You might find this post helpful if you have any problems getting the debug connection to work. (The WingIDE docs also do a decent job of covering connection problems.)
无需通过 Process 启动函数或类,只需直接调用它并像平常一样进行调试即可。
Rather than starting your function or class via Process, just call it directly and debug as you normally would.