从Jupyter Notebook退出pdb交互模式 [英] Exit pdb Interactive Mode from Jupyter Notebook

查看:470
本文介绍了从Jupyter Notebook退出pdb交互模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在pdb中,我正在使用interact命令进入交互模式(文档位于 https ://docs.python.org/3/library/pdb.html ). 这使我在pdb中有了一个InteractiveConsole(我需要它来进行列表理解). 在Jupyter Notebook中,如何在不完全退出调试器的情况下退出交互模式?

Within pdb, I'm using the interact command to enter interactive mode (documentation at https://docs.python.org/3/library/pdb.html). This gives me an InteractiveConsole within pdb (which I need in order to do list comprehension). From within a Jupyter Notebook, how do I leave interactive mode without exiting the debugger entirely?

我尝试过的事情:

  • 下面的链接回答了这个确切的问题,但是解决方案仅在终端上有效.从Jupyter内部按Ctrl-d只会添加一个书签...而quit()返回: NameError:名称"quit"未定义
  • The link below answers this exact question but the solutions only work from the terminal. Ctrl-d from within Jupyter just adds a bookmark...And quit() returns: NameError: name 'quit' is not defined

在Python中调试器pdb,如何在不终止调试会话的情况下退出交互模式

  • 打坐.情况不变.

我可以导入sys; sys.exit(),但这会完全退出调试器,这意味着我必须从头开始.

I can do import sys; sys.exit(), but that exits the debugger entirely, meaning I have to start from scratch.

推荐答案

我成功的唯一方法是从另一个来源复制/粘贴Crtl-D字符.我使用Emacs,所以这相当容易,但是任何允许您在文档中插入Crtl-D的文本编辑器都可以使用.插入后,在pdb交互字段中使用标准的复制/粘贴,然后按或.这应该让你离开.

The only way I have been success is to copy/paste the Crtl-D character from another source. I use Emacs, so this is fairly easy, but any text editor that allows you to insert a Crtl-D into the document should work. Once inserted, use the standard copy/paste into the pdb interact field and hit or . This should get you out.

出于Emacs的演示目的,很长的路要走如下所示:

For Emacs, the long way is as follows, for demonstration purposes:

M-x insert char <RET> END OF TRANSMISSION <RET>

这时,您应该在缓冲区中看到^ D.此时,选择角色并保存M-w或kill-ring-save将其放置在剪贴板上.

At this point you should see ^D in the buffer. At this point select the character and M-w or kill-ring-save to put it on the clipboard.

然后,切换到浏览器并使交互式字段处于活动状态,然后将字符粘贴回去.您将看不到任何东西.然后打.这应该/可能使您摆脱困境.

Then, change to the browser and make the interactive field active, and paste the character back. You will not see anything. Then hit . This should/might get you out.

这篇关于从Jupyter Notebook退出pdb交互模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆