Exiting Python Debugger ipdb

后端 未结 6 1003
被撕碎了的回忆
被撕碎了的回忆 2020-12-25 11:15

I use ipdb fairly often in a way to just jump to a piece of code that is isolated i.e. it is hard to write a real script that uses it. Instead I write a minimal tes

相关标签:
6条回答
  • 2020-12-25 11:20

    I put the following in my .pdbrc

    import os
    
    alias kk os.system('kill -9 %d' % os.getpid())
    

    kk kills the debugger and (the process that trigger the debugger).

    0 讨论(0)
  • 2020-12-25 11:31

    The following worked for me:

    import sys
    sys.exit()
    

    On newer versions of ipython, as mentioned above and below, this doesn't work. In that case,

    import os
    os._exit(0)
    

    should still do the trick.

    0 讨论(0)
  • 2020-12-25 11:31

    Sloppy but effective way is to set monkey patch ipdb.set_trace = lambda:0, then every subsequent time ipdb.set_trace is hit it will do nothing and return to the calling function. So you won't have to type q any more.

    0 讨论(0)
  • As mentioned in another answer, this was a bug in IPython 5.1. It was fixed in this pull request and is no longer an issue from IPython 5.2 and onwards. You can now use q, quit(), or Ctrl+d to exit the debugger.

    0 讨论(0)
  • 2020-12-25 11:37

    It's the problem with the recent version of IPython 5.1.0. You can check with your environment using the following code:

    pip freeze | egrep -i '^i'
    

    It will be resolved by downgraded to IPython==5.0.0.

    pip install ipython==5.0.0
    

    That works for me.

    0 讨论(0)
  • 2020-12-25 11:43

    I've found these solutions only succeed in breaking your kernel, and then you have to restart and load everything again.

    The problem I was having was in a for loop q will just proceed to the next iteration instead of quitting out of the loop. Eventually I figured out it only happens if your for loop is in a try statement. Remove the try and you can quit out of the debugger again without it continuing the for loop.

    0 讨论(0)
提交回复
热议问题