Python Debugger Freezing After 5 Lines of Code - python

What to do when the python debugger seems to get stuck after running the first few (five) lines of code?
I have been using Python for quite a while, but starting yesterday, I have not been able to use the debugger. Whenever i try to run the debugger, it just displays the first 5 lines of the script and then stops.
If I then try to exit out of the debugger, it just displayer --KeyboardInterrupt-- but it does not terminate the process.
I am running Python 3.9 with Spyder, and have tried fixing it by restarting, resetting to factory setting, installing into a new environment, as well as a total uninstall and clear, and then installing from scratch, but nothing seems to work.
Even when i try running really basic scripts (like the images below) the result is the same
Running basic scripts normally (F5) works fine
But debugging just gets stuck
And terminating the debugger process is not possible

Related

Visual Studio Code Python Debugger Missing Other Threads in Call Stacks

Basic Info
Environment: Windows 11
Python Version: 3.8.10
Use virtual env: Yes
VSCode Python extension version: v2022.20.2
Problem
I tried running an Odoo 15 (multi-threaded) application and previously I was able to see that VSCode properly tracked all spawned thread.
However yesterday when I tried to debug my application, I noticed that my breakpoints on code that was supposed to be run on spawned threads weren't hitting (main thread is fine).
After looking at the call stack window, I noticed that what used to be a list of threads are now showing nothing as if there's only 1 thread running.
Figure 1. Call stack on my Odoo program
So I'm wondering that it has something to do with my VSCode settings, but I'm drawing a blank on which. Interestingly, on my colleague's Linux machine, he can debug and see all the threads fine with VSCode
I've tried to do a clean uninstallation of VSCode and re-installed all extensions manually, but to no avail.
Interestingly, I tried writing a simple threaded program (with threading lib, same as Odoo's) and the call stack showed the multiple threads fine, so I'm lost as of why
Figure 2. Call stack on my simple threaded programs
Turns out I have an entry in my .env GEVENT_SUPPORT=True.
Once I erased that flag, everything works normal

Python Process (Activity Monitor) Doesn't Stop

I recently started using Python. I realized that even the simplest program starts a Python process that never ends and causes my computer to overheat if I don't manually kill that process.
I've even seen multiple Python processes running at the same time after running a few easy Python programs (Hello, World!) in a row.
I updated to the latest Python version (Python 3.9.3), installed all the Certificates, and tested a few different programs to see if it happens every time—it does. I am using VSC as the IDE but the same situation happens even if I use IDLE.
My questions are: Is this an interpreter issue or a Mac issue? Can it be fixed?
Thank you very much.

Script runs successfully on Spyder but not directly in Python

This a conceptual question. What reasons could motivate that a script runs successfully on Spyder IDE but not directly in Python. I am in Win7-64x. I think it is because Spyder is somehow more lenient.. maybe it uses hidden modules, libs, bats..? I found this problem when I was trying to make an executable using Pyinstaller, so I step back and check running the myscript.py on python directly like this on cmd,
python myscript.py
and it runs the script but throws normal errors like "list index out of range". The thing is they don't appear if executed inside the Spyder IDE, the script in Spyder is run fine without errors. I don't know the possible reasons. There is a way to roundabout that for pyinstaller, so that the produced executable runs fine like in Spyder? Suggestions? (Win7-64x, Python3.6, Spyder3.3.3)

Restart IPython kernel

I am using Anaconda/Iphython 32bit on a Windows machine wit Python version 2.7. Every time I run a script (different Modules are called) and it fails, I need to close the program and open it again if I want to change the code. If I change the code without closing/opening IPython, my changes in the code are not “updated”.
I tired %reset, but it does not work. I tried ‘Ctrl’, ‘Ctrl+’. and ‘Crtl-‘ without success (nothing happen).
It is really annoying because I have to change the Conda environment everytime and restart IPython :).
Any tips? Would be great

Does python have a limitation on the amount of code in a module?

I have written a Python module designed to solve the Tetris cube tiling puzzle, and it contains a lot of code, but it doesn't want to run, when I press f5 to run the program, the shell restarts, but then stops working, even when I enable debugging nothing happens still. I put a print statement at the very start of the program, yet it is not executed, and I cannot terminate the program using ctrl-c. I was able to fix this problem by putting some of the functions I had defined into a separate module, and now it works fine, but if I create a new function, and add enough print statements, the problem reappears, but can be fixed by just removing one statement.
The version of Python I am using is Python 2.7.8
The problem seems to have been an issue with the version of python I had installed. A new installation is able to run long modules fine, without any noticeable delay even from pressing f5 to first print statement.

Categories

Resources