You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tried the other applicable steps from the Troubleshooting Guide
Completed the Problem Description, Steps to Reproduce and Version sections below
Problem Description
There currently doesn't exist a graphical way to pause currently running code and drop to ipdb, which causes problems when debugging larger code bases and trying to see what is going on when things have unexpectedly frozen. There needs to be a way to drop to pdb and see what is going on when this happens, and also be able to type "c" in pdb and resume.
This was also noted in #16430, where it was stated that the main problem seems to be that there is no way to integrate this with the Spyder debugger.
Well, there does seem to be a way to do this which currently works very well with Spyder. Here is a very simplified version of the basic idea:
import pdb
def debug_signal_handler(signal, frame):
pdb.Pdb().set_trace(frame)
signal.signal(signal.SIGINT, debug_signal_handler) # ctrl c
while True:
pass
And now, any time you type Ctrl-C, it will immediately go to IPdb, where you can see what is going on and/or press "c" to resume.
As far as I can tell, this basic setup seems to integrate perfectly with Spyder. If you set this in your startup script, Ctrl-C will simply bring up a debugger, and it's about as simple as that. It seems to work very well, integrate with breakpoints set both graphically and in IPdb, and so on.
There are a zillion variations and ways to build on this idea, but the point is they all work, so the main request is just to make a button or checkbox for this in the UI somewhere.
Here are two suggestions that seem as though they'd be pretty easy:
Just add a checkbox somewhere in the UI that toggles if SIGINT is being captured for the current kernel. Whenever it's checked, the current kernel runs something like signal.signal(signal.SIGINT, debug_signal_handler). Whenever it's unchecked, the kernel runs something like signal.signal(signal.SIGINT, signal.SIG_DFL). About as simple as it gets.
You could leave the default Ctrl-C behavior as-is and capture something like SIGUSR1 instead (although I'm not sure what you'd do for Windows, perhaps SIGBREAK). Or perhaps SIGTSTP, generated by Ctrl-Z. Either way, you can then create a new button or menu entry called "Pause" which just sends that message to the kernel.
And probably a million other ideas.
I would be willing to submit a PR for this if there's interest and people can tell me which of the above methods they'd prefer. I would probably prefer the second, unless we also added some way to make this on by default, because I'm sure I'll forget to turn it on for every new kernel I start.
Versions
Spyder version: 5.4.2 (conda)
Python version: 3.10.9 64-bit
Qt version: 5.15.6
PyQt5 version: 5.15.7
Operating System: Darwin 21.6.0
The text was updated successfully, but these errors were encountered:
ccordoba12
changed the title
Feature request: Graphical way to pause at current point and drop to debugger
Graphical way to pause at current point and drop to debugger
Feb 23, 2023
Issue Report Checklist
conda update spyder
(orpip
, if not using Anaconda)jupyter qtconsole
(if console-related)spyder --reset
Problem Description
There currently doesn't exist a graphical way to pause currently running code and drop to ipdb, which causes problems when debugging larger code bases and trying to see what is going on when things have unexpectedly frozen. There needs to be a way to drop to pdb and see what is going on when this happens, and also be able to type "c" in pdb and resume.
This was also noted in #16430, where it was stated that the main problem seems to be that there is no way to integrate this with the Spyder debugger.
Well, there does seem to be a way to do this which currently works very well with Spyder. Here is a very simplified version of the basic idea:
And now, any time you type Ctrl-C, it will immediately go to IPdb, where you can see what is going on and/or press "c" to resume.
As far as I can tell, this basic setup seems to integrate perfectly with Spyder. If you set this in your startup script, Ctrl-C will simply bring up a debugger, and it's about as simple as that. It seems to work very well, integrate with breakpoints set both graphically and in IPdb, and so on.
There are a zillion variations and ways to build on this idea, but the point is they all work, so the main request is just to make a button or checkbox for this in the UI somewhere.
Here are two suggestions that seem as though they'd be pretty easy:
Just add a checkbox somewhere in the UI that toggles if SIGINT is being captured for the current kernel. Whenever it's checked, the current kernel runs something like
signal.signal(signal.SIGINT, debug_signal_handler)
. Whenever it's unchecked, the kernel runs something likesignal.signal(signal.SIGINT, signal.SIG_DFL)
. About as simple as it gets.You could leave the default Ctrl-C behavior as-is and capture something like SIGUSR1 instead (although I'm not sure what you'd do for Windows, perhaps SIGBREAK). Or perhaps SIGTSTP, generated by Ctrl-Z. Either way, you can then create a new button or menu entry called "Pause" which just sends that message to the kernel.
And probably a million other ideas.
I would be willing to submit a PR for this if there's interest and people can tell me which of the above methods they'd prefer. I would probably prefer the second, unless we also added some way to make this on by default, because I'm sure I'll forget to turn it on for every new kernel I start.
Versions
The text was updated successfully, but these errors were encountered: