0

So I import a module:

from IPython.core.debugger import Pdb

Then I initiate an object for debugging:

ipdb = Pdb()

I define a function to test debug mode:

def f(a=1):
    ipdb.set_trace()
    print(a)

After I run the function:

f()

I am in the debug mode, in this mode, I can quit easily with q, however, after I type

interact

to get in the interactive mode(because in this mode I can input multiple line code rather than one line code to run more complicated functional codes)

I can't quit this mode unless I kill the whole Python Jupyter session(like kill the kernel), I have tried quit(),quit,q(),q,exit(),exit,ctrl+C and ctrl+D ,None of them work.

I checked the source code of the IPython.core.debugger module and didn't get helpful info.

Does anyone know how to get out of this interactive session?

8
  • 1
    This might help: stackoverflow.com/questions/36945059/… Commented Aug 11 at 3:53
  • @Ranger Thanks for the suggestion but none of the answer works for me Commented Aug 11 at 6:34
  • One of the answers in the link Ranger provided worked fine with your test example in the session you'll get if you go here and press the 'launch binder' to get a remote session. If you do that and then follow your MRE, you can follow this particular answer, which led me Exiting interact mode in %%debug cell led me to here ... Commented Aug 13 at 2:53
  • <continued> where the comment just above there led me to this SO comment that described a command that worked in the terminal on MY LOCAL MAC to get the special character in the clipboard which I could then paste into the interactive pdb prompt. That gave me now exiting InteractiveConsole... and then I still needed to exit the ipdb> level. I did that with q. So the trick is getting the special character from somewhere on your machine. .... Commented Aug 13 at 3:00
  • 1
    @Wayne I think I solved the problem in windows local env, thanks for your suggesion: "It's just that making it effectively work can be super tricky depending on your system" which shed lights on me to figure out the solution. Commented Aug 14 at 6:25

1 Answer 1

0

I think I figure out the solution myself, I want to post the solution for windows local machine here; thanks for @Wayne 's suggestion that "It's just that making it effectively work can be super tricky depending on your system".

I open the powershell of windows, type the following command

[System.IO.File]::WriteAllBytes("$env:TEMP\ctrl-d.txt", @(4))

Then I open the file using command:(Open a folder,type the following command in the address field)

%TEMP%\ctrl-d.txt

then ctrl-A + ctrl-C to copy the character to clipboard in windows system

paste that character into the interactive mode prompt

I am able to get back to ipdb normal mode instead of interactive mode.

You can see the result in the picture:

enter image description here

By the way, I really think they should give an easy way to quit the mode, it cost me several days to figure this out...

Sign up to request clarification or add additional context in comments.

2 Comments

In reference to this, "By the way, I really think they should give an easy way to quit the mode, it cost me several days to figure this out...". You are using something meant for the terminal/console in modern Jupyter instead of current Jupyter practices for debugging. IPython and Jupyter had the big split a decade ago. Some would argue if you want to use IPython, you can use IPython directly. Jupyter has visual debugger that will show you current variable states and allow you to step through code. It also has consoles you can attach so you can paste in code blocks separate from notebook ...
<continued> code cells. So if you want to use Jupyter, I would explore more the modern ways to debug and develop in there. Likely you will want to be using JupyterLab, by the way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.