如何在pydev中启用事后调试?

时间:2012-08-10 10:06:21

标签: python debugging pydev

每当我的程序引发未处理的异常时,我想让pydev进入交互式控制台模式,但我无法弄清楚如何做到这一点。正如它现在所表现的那样,报告了异常,并且该过程被立即终止。

经过一番搜索,我发现了这个: http://sourceforge.net/tracker/index.php?func=detail&aid=3029746&group_id=85796&atid=577332 建议使用pydevd.set_pm_excepthook()

然而,当我添加

import pydevd
pydevd.set_pm_excepthook()

到我的代码,我得到一个例外:

This function is now replaced by GetGlobalDebugger().setExceptHook and is now controlled by the PyDev UI.')
DeprecationWarning: This function is now replaced by GetGlobalDebugger().setExceptHook and is now controlled by the PyDev UI.

可是:

GetGlobalDebugger().setExceptHook()

似乎不起作用,GetGlobalDebugger()在全局命名空间中不存在。

2 个答案:

答案 0 :(得分:4)

实际上,您不需要以编程方式执行此操作...您可以转到调试视角> pydev>管理异常断点并检查“暂停未捕获的异常”。

答案 1 :(得分:2)

好的,经过一段时间我发现了显而易见的,代码应该是:

import pydevd
pydevd.GetGlobalDebugger().setExceptHook(Exception, True, False)

捕获任何未编码的异常。当程序崩溃时,该方法可以以其他方式用于进入调试模式,如setExceptHook的 doc 中所述:

  

应该调用来设置要处理的异常以及是否   应该打破未被捕获的           抓住了例外。

     

只能在某些例外情况下接收参数。

    E.g.:
        set_pm_excepthook((IndexError, ValueError), True, True)

        or

        set_pm_excepthook(IndexError, True, False)

        if passed without a parameter, will break on any exception

    @param handle_exceptions: exception or tuple(exceptions)
        The exceptions that should be handled.

    @param break_on_uncaught bool
        Whether it should break on uncaught exceptions.

    @param break_on_caught: bool
        Whether it should break on caught exceptions.

我希望这会帮助其他想要在eclipse中使用pydev调试器来调试程序的人。