Spyder debugger freezes on second restart of code - debugging

My task is to repeatedly rerun a code from beginning. As I do not want to run the code to the end I set a breakpoint() command. However, Spyder freezes when the code is the second time called from debug mode. For demonstration a simple program is sufficient:
print('Hello World!')
breakpoint()
After launching Spyder I start the small program by F5. Everything works as expected and I jumped into the debug mode. Now I press again F5 and the code restarts correctly from the debug mode. After again pressing F5 the code is not restarted and instead the IDE freezes. It is not possible by any means to rerun the code again from debug mode. Interrupting the kernel by pressing the red button (see screenshot below) does not help. Trying to leave the debug mode by !q does not leave the debug mode. The only possibility to rerun the code is quite cumbersome, i.e. I have to restart the kernel (Ctrl+.) that takes a while. How to debug code under these circumstances?
Is this a bug of the IDE or expected behavior? How can I restart the code by a simple key press as often as possible from debug mode?
This is a screenshot of the Spyder console with comments in red added.
I use a recent version a WinPython with latest Spyder 5.4.0, Python 3.10.4 64-bit, Qt 5.15.2, PyQt5 5.15.6, Windows 10Pro Version 21H2. The problem also appears with Spyder 5.3.3 A similar problem (or maybe the same) appears with a different Python version.

After many trials, I noticed that there is something strange with IPython console. I noticed that when it hangs after running a code, if I delete all user variables, it worked fine.
Then I tryed to delete all variables before execution, and it work fine.
Therefore I discovered that a solution that worked for me is to go to preferences -> Run -> and untick the option 'Remove all variables before execution'
It is quite annoying because I have to do it manually every time before running, but in this way the spyder does not appear to hang anymore! I hope that the Spyder developers will solve it soon.
-
I automatically solved by typing at the beginning of any script these lines, inspired from the question Code to clear console and variables in Spyder :
try:
from IPython import get_ipython
get_ipython().magic('clear')
get_ipython().magic('reset -f')
import matplotlib.pyplot as plt
plt.close('all')
except:
pass
similar to Matlab in which you normally start your code with
clc
close all
clear all

Related

Why is my Pycharm debug console not loading?

I recently installed Pycharm on a fresh PC. Unfortunately something seems to be off with the installation. When I try to enter the debug console this isn't loading. E.g. for a very simple test case
def test_stable():
1 == 1
2 == 2 # breakpoint in this line
when I add a breakpoint in the last line, it is stopping the execution correctly, but I can't enter the console (i.e. the little wheels keep spinning):
What is wrong with my installation here? Is this a known issue?
Edit:
When clicking the "Show Python Prompt" button a console opens, but the console is not working, there is no output from it:
As I said above I believe this is connected to the strange behavior in the Debug Console tab.
Edit 2:
As recommended by #bad_coder I changed the test to
class Test:
def test_trivial(self):
test = 5
assert 1 == 1 # breakpoint on this line
I still can't use the debug console. I also just started up my old system and can now confirm that there when clicking on console I am directly getting to the console and not the situation of my first image (with the animated spinning wheels).
The button you're looking for is the Python-with-a-prompt button, which switches between the console and test progress.
If someone stumbles across the same issue, I believe the problem here was basically just that the Pycharm version was rather old. After downloading the current version everything works fine.

Vscode debugger quits as soon as it starts?

I didn't change any configuration settings, but python debugger in vscode malfunctions.
When I use breakpoint() explicitly, it works,
but when I use F5 to start debugging, it automatically ends without any execution.
I googled all the spaces, but I cannot find the reason why debugger does not work.
(It originally worked.)
I sincerely need your help.

visual studio code "launch json" on run, how to set debug console as default

I went to user settings to set the debug console to default (when I try to debug now the default console is terminal. I lose the small debug icons to skip, stop etc even when I manually select debug console). I am watching Python tutorials using Vs Code and his default is debug. How can I do this?
Secondly, when I try to run or debug, I am prompted to open LaunchJS, even if it is already open. I attempted to run it using the debug selection "current file, integrated terminal" and also "Python: Attach". Neither will work although the JSON file has these options. I looked at some MS videos but I am not understanding the problem.
Any help is appreciated. Thanks.
I found the answer at this link: https://code.visualstudio.com/docs/python/python-tutorial
I had not selectd a Python interpreter which establishes a python workspace. Was just trying to run with debugger. A simple program now runs. My guess is that the Python tutorial I selected is too old to follow with this version of VS Code, since I am unfamiliar with any version of VS Code.
Thanks.

ZeroBrane IDE - "run to cursor" (Ctrl+Shift+F10) mode *sometimes* not working during debug

I use ZeroBrane studio (ZBstudio) for debugging Lua code when working with the Torch framework.
A weird issue occurs at times. When debugging, sometimes I want to run the code all the way until it encounters a breakpoint. This specific mode does not work at times (sometimes it does, sometimes it doesn't; I can't figure out why).
When it doesn't work, nothing happens when I press the relevant button in the GUI (or Ctrl+Shift+F10). I can go line-by-line (Shift+F10) when this happens, the line-by-line mode is not affected.
Sometimes when this happend, restarting the ZeroBrane IDE program fixed it, other times it remains persistant.
Not sure if anyone else encountered this strange behaviour. Thanks in any case.

Interactive pyDev console at breakpoint

I'm using Aptana Studio with Pydev 1.5.3 to debug my Django applications. I use PyDev's remote debugger and some code in manage.py and for most of the time this setup is working successfully- I can set breakpoints, inspect variables and step/continue through my code.
However, I'd like to execute arbitrary code at the breakpoint- the thing I really miss after switching from pdb to Eclipse debugging. There is an interactive console available in debug perspective but it is inactive for me.
So my question- is it possible to set up an interactive console in PyDev with remote debugger which could "inject" code at breakpoint?
strange, i am using pydev 1.5.6 for remote debugging and I can use the interactive console - i type the cmmand, hit enter, after a while get results back; check your firewall is not blocking anything (if you are sure, the interactive console works in local mode). there is even settings in pydev source code to set how much of stdout should be returned back to client (in chars), it should work
After some digging I discovered that I can use Expressions view to access variables properties and view results of class methods, but that still isn't a complete console at breakpoint though.
With PyDev 1.5.5 it should be possible:
In "Variables" view, you can right-click on a name, then select "change value".
The console is working as well, albeit a bit tricky.
It is only for inspection and in a very strange way: you have to input the text in the "Debug server" console, and you will get the output in the "filename" console.
Note also that you need to press enter twice, leaving an empty line.
While the "empty line" trick is documented, the issue about two different console for input and output is not, and I think it may be a bug.
On my development stack running Apache + mod_wsgi entering commands into the console had their output routed to the site's error logs. To resolve this you have set the stdoutToServer=True and sterrToServer=True to route capture all output to the PyDev remote debugger:
from pydevsrc import pydevd;pydevd.settrace('192.168.2.8', stdoutToServer=True, stderrToServer=True) #clone and put on python path: https://github.com/tenXer/PyDevSrc

Resources