使用IPython进行断点引发的交互式调试 [英] Breakpoint-induced interactive debugging of Python with IPython

查看:805
本文介绍了使用IPython进行断点引发的交互式调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个IPython会话,我从中调用一些脚本:

 >运行my_script.py 

有没有办法在 my_script中引发断点。 py 我可以从IPython检查我的工作区?



我记得读过以前版本的IPython可以做的:

 从IPython.Debugger import Tracer; 

def my_function():
x = 5
Tracer()
print 5;

但子模块 Debugger 似乎不可用了假设我有一个IPython会话已经打开了:如何停止我的程序我选择的位置,并使用IPython检查我的工作区?



一般来说,我希望不需要我预先指定行号的解决方案,因为我希望可能有不止一个这样的呼叫 Tracer()以上,而不必跟踪他们的行号。

解决方案

在不同模块中的ipython中仍然存在 Tracer()。您可以执行以下操作:

 从IPython.core.debugger import Tracer 

def my_function() :
x = 5
Tracer()()
打印5

请注意在 Tracer附近的附加调用圆括号



编辑追踪器 已弃用你应该使用 set_trace()而不是


Say I have an IPython session, from which I call some script:

> run my_script.py

Is there a way to induce a breakpoint in my_script.py from which I can inspect my workspace from IPython?

I remember reading that in previous versions of IPython one could do:

from IPython.Debugger import Tracer;     

def my_function():
    x = 5
    Tracer()
    print 5;

but the submodule Debugger does not seem to be available anymore.

Assuming that I have an IPython session open already: how can I stop my program a location of my choice and inspect my workspace with IPython?

In general, I would prefer solutions that do not require me to pre-specify line numbers, since I would like to possibly have more than one such call to Tracer() above and not have to keep track of the line numbers where they are.

解决方案

The Tracer() still exists in ipython in a different module. You can do the following:

from IPython.core.debugger import Tracer

def my_function():
    x = 5
    Tracer()()
    print 5

Note the additional call parentheses around Tracer

edit: Tracer is deprecated you should use set_trace() instead

这篇关于使用IPython进行断点引发的交互式调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆