简体   繁体   English

发生错误后,如何让Spyder暂停执行?

[英]How can we get Spyder to pause execution after an error has occurred?

I'm debugging a program, and I would like it if Spyder could pause execution at an error. 我正在调试程序,如果Spyder可以在出现错误时暂停执行,我希望它能正常运行。 I had read previously that this can be done without breakpoints by just running scripts in Debug mode, but that isn't working for me. 之前我已经读过 ,只需在Debug模式下运行脚本就可以在没有断点的情况下完成此操作,但这对我不起作用。

Eg, when I run the following script in Debug mode in Spyder, it just errors out at the index out of range exception without giving me any opportunity in ipdb to play with the variables. 例如,当我在Spyder中以调试模式运行以下脚本时,它只是在索引超出范围异常时出错,而没有给我任何机会在ipdb中使用变量。

import numpy as np   

A = np.random.randn(5)

A[7] = 8 #IndexError

More specifically, when I start debug, it starts me at the first line, then when I press Continue, execution proceeds all the way through line 3 without giving me a chance to inspect the workspace before execution exits. 更具体地说,当我开始调试时,它在第一行启动我,然后当我按继续时,执行一直进行到第3行,而没有给我机会在执行退出之前检查工作区。

Any thoughts? 有什么想法吗?

Thanks. 谢谢。

I guess that if you launch your script under the "Run" > "Configuration per file" window and check "Directly enter debugging when errors appear" you get what you need. 我猜想,如果您在“运行”>“每个文件的配置”窗口下启动脚本,然后选中“出现错误时直接输入调试”,您将获得所需的内容。 You should then run the script normally (not in debug mode). 然后,您应该正常运行脚本(不在调试模式下)。

you need to add a breakpoint in your code, after start your debug mode, it will stop at the line where your break point ocurrs. 您需要在代码中添加一个断点,启动调试模式后,它将在发生断点的行处停止。 Then, don't press continue, on the right of continue button there is a button that allow you to execute current line. 然后,不要按继续,在继续按钮的右侧,有一个按钮可以让您执行当前行。 It will execute your code in current line and move your breakpoint into next line. 它将在当前行执行您的代码,并将断点移至下一行。 So you can check your code line by line. 因此,您可以逐行检查代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM