Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm: how to do post mortem debugging in the ipython interactive console?

I've just started using the nice PyCharm community edition IDE, and can't do a simple thing that is part of my usual Python workflow.

I've started an ipython console and I can import my modules and interactively run commands. In PyCharm when I execute a function call, it is executed like it was running in a separate process. The console prompt can be used even before the execution finishes. It is nice but prevents me to do post mortem debugging.

Running ipython in a shell outside PyCharm, when an exception happens, I can run pdb's post mortem feature and investigate the problem:

import pdb;pdb.pm()

I want to do the same in PyCharm: start post mortem debugging when an exception happens while I'm interactively investigating a problem.

like image 478
neves Avatar asked Oct 21 '16 20:10

neves


2 Answers

Given that you are using PyCharm, why not use the built-in debugger? There is ample documentation on how you can use it to set your own breakpoints, step through your stack, configure the debugger options etc.

Specifically for your use case, if you want to break on exceptions -- you can use Ctrl + Shift + F8 to open the breakpoints configuration screen. Breakpoints You can then check to break on Any exception for Python Exception Breakpoint. This would give you access to the exception and the entire stack (in the Frames section), context, variables etc. when something does happen.

like image 120
Vlad B Avatar answered Oct 25 '22 18:10

Vlad B


It is possible in IPython to use the %pdb magic.

Simply use %pdb on IPython and whenever an error occurs you will be dropped in an ipdb session with the Post Mortem of the error.

I don't really know if this works in PyCharm.

(I found this answer here some time ago)

like image 22
renan-eccel Avatar answered Oct 25 '22 18:10

renan-eccel