This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: IDLE Debugger should handle interrupts
Type: behavior Stage: patch review
Components: IDLE, Windows Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: louielu, ltaylor934, markroseman, terry.reedy
Priority: normal Keywords: patch

Created on 2012-02-24 19:47 by ltaylor934, last changed 2022-04-11 14:57 by admin.

File name Uploaded Description Edit ltaylor934, 2012-02-24 19:47 Trivial cpu-intensive loop
Issue14111.patch roger.serwy, 2012-02-27 05:30 review
0001-WIP.patch louielu, 2017-05-24 09:38
Pull Requests
URL Status Linked Edit
PR 1821 open louielu, 2017-05-26 04:04
Messages (11)
msg154150 - (view) Author: Larry A. Taylor (ltaylor934) Date: 2012-02-24 19:47
The attached script runs a long processing loop.

Start it in IDLE. Open the script and run it.

Press control-C. Result: message, KeyboardInterrupt with traceback message.

In shell window, turn on Debugger. Run the script.

Press control-C. Result: Restrat message shown in Python Shell. Debug Control shows no change.

Expected behavior: For keyboard interrupt, or for any uncaught exception, Debug Control should show the same information as if there was a breakpoint. For instance, the stack with line numbers, locals and globals.

Better: make a way to interrupt the program in a long loop or process, so that the programmer can tell -- live -- where the program is, and where most of the time is being used. Then use the regular buttons, Go, etc. to continue the process, possibly interrupted again.

Also: the IDLE Python Shell and Debug Control show no "running" indicator, so there is no easy way to tell if the program is still going.
msg154433 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-02-27 05:30
I can confirm the issue Larry's raises. Attached is a patch against 2.7 to enable Ctrl+C interrupts for the debugger. The patch opens up the possibility of making "Go" a toggle button, but that would require some more plumbing (not included in patch).

A "run" indicator should be simple to implement. The status bar can contain a label that can be updated with calls to "beginexecuting" and "endexecuting" in
msg265100 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-07 22:56
'raise KeyboardInterrupt' in code causes shell to hang until Restart Shell Cntl-F6 in invoked.

>>> raise KeyboardInterrupt
<debug window activates.  Hit [step].  Window deactivates.  No prompt, even in response to Enter.  Shell unresponsive.>
<Restart Shell>
=============================== RESTART: Shell ===============================

The behavior was noted by pperry on #26949, which is about SystemExit behavior.  I currently think it part of this issue.
msg265103 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-07 23:13
More info: Even though the debug window looks inactive, it is not.  After the restart, debugger cannot be turned off because it is 'active'.  It must be stuck on the raise statement.  The window can be closed, but after that, it cannot be brought back because something is still going.  It takes another Restart to restart debugger.
msg294330 - (view) Author: Louie Lu (louielu) * Date: 2017-05-24 07:12
The reproduce step can be reduce to:

1. open idlelib with debugger (./python -m idlelib -d)
2. enter print() (or any other function call)
3. Control-C breakout

Then it will restart the shell.
msg294338 - (view) Author: Louie Lu (louielu) * Date: 2017-05-24 09:38
Update roger's patch to current version.

Is there any reason this patch isn't merged? The problem in #26949 is a separate issue about this problem.
msg294447 - (view) Author: Louie Lu (louielu) * Date: 2017-05-25 08:26
Roger, will you convert the patch to GitHub PR? The patch runs will, there are only two point need to add: 

  1. user_interrupt should clear sys.settrace when step in
  2. cancel_callback add a interp.write("\nKeyboardInterrupt\n")

msg294483 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-05-25 14:42
Roger, Python development has moved from hg and out private server to git and GitHub.  Patches posted on the tracker must be converted to git pull requests (PRs) to be merged, and also for proper review and editing.  Unless you prefer to do it yourself, we will.  The only difference is the 'author' field of the PR.  Credit in the commit message and news entry remains as it was.

Louie, make a PR for this any time you want to.  I do not expect a quick response either way.  The original commit should be the patch as is other than necessary updates for 3.7, and identified as Roger's in the commit message.  Then make your changes in separate commits.
msg294530 - (view) Author: Louie Lu (louielu) * Date: 2017-05-26 04:06
The patch is upload to PR 1821, if Roger get a GitHub account and linked to b.p.o, we can rebase the first commit and change the author in commit message to Roger's account information.
msg382320 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-02 15:25
Mark, since you are working on redoing the debugger gui, do you have any opinion on this?  The basic idea is that ^C when debugging should just interrupt the remote process, not end it, just as when there is no debugger.  I agree.

I just updated the PR to current master but have not at the moment tested it.
msg382537 - (view) Author: Mark Roseman (markroseman) * Date: 2020-12-04 22:09
Terry, I agree that Ctrl-C should act just as an interrupt when the debugger is active. I also agree that a way to interrupt the debugger through the user interface is needed (in the revised UI, there's an explicit 'stop' button for that).
Date User Action Args
2022-04-11 14:57:27adminsetgithub: 58319
2020-12-04 22:09:27markrosemansetmessages: + msg382537
2020-12-02 15:25:06terry.reedysetnosy: - roger.serwy

messages: + msg382320
versions: + Python 3.10, - Python 3.7
2017-05-26 04:06:24louielusetmessages: + msg294530
2017-05-26 04:04:53louielusetpull_requests: + pull_request1907
2017-05-25 14:42:05terry.reedysetassignee: terry.reedy
messages: + msg294483
versions: + Python 3.7, - Python 2.7, Python 3.5, Python 3.6
2017-05-25 08:26:03louielusetmessages: + msg294447
2017-05-24 09:38:24louielusetfiles: + 0001-WIP.patch

messages: + msg294338
2017-05-24 07:12:06louielusetnosy: + louielu
messages: + msg294330
2016-05-07 23:13:58terry.reedysetmessages: + msg265103
2016-05-07 22:56:25terry.reedysettype: enhancement -> behavior
stage: patch review
messages: + msg265100
versions: + Python 3.6, - Python 3.4
2015-09-18 16:40:52markrosemansetnosy: + markroseman
2014-07-30 21:51:19BreamoreBoysetversions: + Python 3.5, - Python 3.3
2013-06-15 18:53:18terry.reedysetversions: + Python 3.3, Python 3.4
2012-02-27 05:30:03roger.serwysetfiles: + Issue14111.patch

nosy: + terry.reedy, roger.serwy
messages: + msg154433

keywords: + patch
2012-02-24 19:47:19ltaylor934create