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.

classification
Title: IDLE restarts when one debugs code raising SystemExit
Type: behavior Stage: test needed
Components: IDLE Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: louielu, ppperry, terry.reedy
Priority: normal Keywords:

Created on 2016-05-04 12:49 by ppperry, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 1711 open louielu, 2017-05-22 06:44
Messages (9)
msg264861 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-04 20:51
To be more specific: if one runs a file, the shell is restarted (with the file name).  In the file, raise SystemExit is normally the same as running off the end of the file, and a prompt is printed.  If one runs a file with debugger on, [DEBUG ON] is printed before the prompt.  However, SystemExit while debugging causes a Restart Shell before the [DEBUG ON] and >>> prompt.  The 2nd restart does not normally happen when debugging finishes.  It does not happen when any other exception is raised; instead a traceback is printed as normal.

This is a minor bug, but it does prevent interactive examination of the process after debugging.

There is special code in run.py to catch SystemExit and not print a traceback.  My guess in a bug in RemoteDebugger.py that causes (allows) the execution process to exit or otherwise get detached from the IDLE process.  When the IDLE process loses contact with the current execution process, it starts a new one.
msg264863 - (view) Author: (ppperry) Date: 2016-05-04 20:56
Terry, Your `how to reproduce` is more complicated than necessary. This bug can be reproduced by just turning on the debugger in a python shell and typing `raise SystemExit` then pressing step in the debugger.
msg264867 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-05 00:16
Thanks, that may make debugging this (and creating a test) easier.  I have only seriously used debugger with files, and often with breakpoints in the file.
msg265097 - (view) Author: (ppperry) Date: 2016-05-07 22:43
This issue has worse consequences than I previously thought. It also affects `KeyboardInterrupt` with worse consequences.

If you run a program raising `KeyboardInterrupt` in the debugger, the shell will hang. Restarting the shell fixes this problem.
msg265101 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-07 22:57
#14111 is about handling ^C while debugging.  So for now I will assume that handling 'raise KeyboardInterrupt' is part of that issue.
msg294124 - (view) Author: Louie Lu (louielu) * Date: 2017-05-22 06:37
The problem is cause by run.py:main function, when it catch KeyboardInterrupt or SystemExit, it won't put a blank msg back to response_queue, that cause the loop in run.py:main triggering except queue.Empty to continue the loop.



So, I think the KeyboardInterrupt hang is a bug, cause by the infinity loop above, but SystemExit will raise SystemExit again, and break down the loop, let the shell restart. I think this isn't a bug.

Let's say there is a code like this:

    x = 10
    print(x)
    raise SystemExit
    print(x)

When using IDLE to run this file without debugger, it will print 10 and leave below code. But when you type "x" in the shell, it will pop up 10, that means the shell environment didn't exit, still exist inside.

But if you open the debugger, let SystemExit break the loop and restart the shell, I think this is a normal behavior -- that it should exit the shell (and restart it)
msg294125 - (view) Author: Louie Lu (louielu) * Date: 2017-05-22 06:46
PR 1711 fix KeyboardInterrupt with adding rpc.repsonse_queue.put, but it will not print out the exception traceback.

And for SystemExit, wait for discussion result.
msg294775 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-05-30 18:27
Louie> If you run your example in Python with -i, you will see the same behavior, except for the traceback, as with IDLE.

F:\dev\cpython>python -i -c "x=10; print(x); raise SystemExit"
Running Debug|Win32 interpreter...
10
Traceback (most recent call last):
  File "<string>", line 1, in <module>
SystemExit
>>> x
10

Ditto for "python -i testfile.py".  I would like the behavior to be the same when debugging.
msg352889 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-09-20 20:57
>>> raise SystemExit does not normally cause a restart.
History
Date User Action Args
2022-04-11 14:58:30adminsetgithub: 71136
2019-09-20 20:57:18terry.reedysetnosy: - kbk, roger.serwy

messages: + msg352889
versions: + Python 3.9, - Python 2.7, Python 3.5, Python 3.6
2017-05-30 18:27:04terry.reedysetmessages: + msg294775
2017-05-22 06:46:16louielusetmessages: + msg294125
2017-05-22 06:44:22louielusetpull_requests: + pull_request1802
2017-05-22 06:37:23louielusetnosy: + louielu
messages: + msg294124
2016-05-07 22:57:59terry.reedysetmessages: + msg265101
2016-05-07 22:43:09ppperrysetmessages: + msg265097
2016-05-05 00:16:03terry.reedysetmessages: + msg264867
versions: + Python 3.5, Python 3.6, - Python 3.4
2016-05-04 20:56:39ppperrysetmessages: + msg264863
versions: + Python 2.7
2016-05-04 20:51:38terry.reedysetmessages: + msg264861
2016-05-04 16:43:21SilentGhostsetnosy: + terry.reedy, kbk, roger.serwy

stage: test needed
2016-05-04 12:49:03ppperrycreate