Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphical way to pause at current point and drop to debugger #20572

Closed
10 tasks done
battaglia01 opened this issue Feb 21, 2023 · 1 comment · Fixed by #18514
Closed
10 tasks done

Graphical way to pause at current point and drop to debugger #20572

battaglia01 opened this issue Feb 21, 2023 · 1 comment · Fixed by #18514

Comments

@battaglia01
Copy link
Contributor

battaglia01 commented Feb 21, 2023

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • 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:

  1. 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.

  2. 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
@ccordoba12
Copy link
Member

Hey @battaglia01, thanks for reporting. This is already implemented and it'll be part of Spyder 6, to be released during the second half of the year:

interrupt--running-process

@ccordoba12 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
@ccordoba12 ccordoba12 added this to the v6.0alpha1 milestone Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants