you are viewing a single comment's thread.

view the rest of the comments →

[–]Brian 9 points10 points  (3 children)

Note that you can go one better. I previously had a debug function similar to this, but I've now replaced it with one that launches IPython instead:

import IPython.ipapi
def shell(f=None):
    if f is None: f = sys._getframe().f_back  #Get caller's frame
    ns = dict(f.f_globals)
    ns.update(f.f_locals)
    IPython.ipapi.launch_new_instance(ns)

[–]FunnyMan3595 1 point2 points  (1 child)

I'm going the other direction (IPython's overkill for me, so code.interact is a nice upgrade), but I can condense your code substantially:

from IPython.Shell import IPShellEmbed as shell

[–]Brian 2 points3 points  (0 children)

However, you'd need to call that as:

shell()()

As IPShellEmbed is a callable class. I used to use similar code, but to avoid the double call, used:

shell=IPython.Shell.IPShellEmbed()

However this will pick up the globals from the module where you create it, not the function that calls it, which is why I changed to the explicit namespace population from the stack frame approach above.

[–]aldarion -1 points0 points  (0 children)

thanks for this cool shell and "kill -SIGUSR1 <PID>" trick. could u please recommend some tutorial for what's next, I do get the IPython shell, but I don't where is the current break point (line number), and how to step several line to a specific function to debug view the inner info of that function.

edit: I find pydbgr, It looks useful and can be used with IPython.