Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging inside PyCharm IPython

Is it possible to hit graphical breakpoints when running codes in PyCharm's IPython console?

i.e.:

  • You have a script foo() in foo.py
  • You place a graphical breakpoint inside foo() from the editor (the red dot next to line number)
  • You import foo into a PyCharm's IPython console and execute foo() (Note: not running from a debug configuration!)
like image 452
reading_ant Avatar asked Mar 24 '14 14:03

reading_ant


3 Answers

As suggested by @bvanlew in comments, PyCharm (both community and professional edition) now supports attaching debugger onto interactive console. Click the debug button as shown below, and PyCharm's debugger will kick in when the breakpoint is hit.

enter image description here

like image 176
reading_ant Avatar answered Oct 29 '22 12:10

reading_ant


Yes, it is. But it is not automatic.

(Using 4.5.2, Windows 8)

I run an IPython Notebook, and let PyCharm kick off the notebook backend.

I hit Tools, Attach to Process and attempt to identify the PID of the notebook process. I'm yet to find a smooth way of doing this. Currently I use Process Explorer, find the pycharm entry, and watch for the new sub-processes after the notebook server starts. You want the leaf python.exe process, e.g:

6268  pycharm.exe
1235    python.exe       (new when notebook launched)
7435      conhost.exe    (new)
9237      python.exe     (new - pick this PID)

I can now run a cell and hit the graphical breakpoints.

Enjoy.

like image 24
psion5mx Avatar answered Oct 29 '22 14:10

psion5mx


On ubuntu i had to change the line kernel.yama.ptrace_scope = 1 in /etc/sysctl.d/10-ptrace.conf to kernel.yama.ptrace_scope = 0 otherwise pycharm was not able to attach to the ipython process.

like image 1
Marti Nito Avatar answered Oct 29 '22 14:10

Marti Nito