Skip to content

Commit 8a7a7a4

Browse files
gh-82183: Do not restart the busy IDLE shell when running without restart
"Run... Customized" with "Restart shell" unchecked restarted the shell anyway when it was busy executing code, killing any pending input. It now reports that the shell is executing and does not run.
1 parent 2303eea commit 8a7a7a4

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lib/idlelib/idle_test/test_runscript.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from idlelib import runscript
44
import unittest
5+
from unittest import mock
56
from test.support import requires
67
from tkinter import Tk
78
from idlelib.editor import EditorWindow
@@ -28,6 +29,26 @@ def test_init(self):
2829
sb = runscript.ScriptBinding(ew)
2930
ew._close()
3031

32+
def test_run_module_event_shell_busy_no_restart(self):
33+
# gh-82183: running without restarting the busy shell aborts.
34+
ew = EditorWindow(root=self.root)
35+
sb = runscript.ScriptBinding(ew)
36+
sb.getfilename = mock.Mock(return_value='test.py')
37+
sb.checksyntax = mock.Mock(return_value='code')
38+
sb.tabnanny = mock.Mock(return_value=True)
39+
sb.shell = shell = mock.Mock()
40+
shell.executing = True
41+
interp = shell.interp
42+
with mock.patch.object(runscript, 'CustomRun') as customrun:
43+
# Restart shell unchecked.
44+
customrun.return_value.result = (['arg'], False)
45+
result = sb.run_module_event(None, customize=True)
46+
self.assertEqual(result, 'break')
47+
interp.display_executing_dialog.assert_called_once()
48+
interp.restart_subprocess.assert_not_called()
49+
interp.runcode.assert_not_called()
50+
ew._close()
51+
3152

3253
if __name__ == '__main__':
3354
unittest.main(verbosity=2)

Lib/idlelib/runscript.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ def run_module_event(self, event, *, customize=False):
139139
return 'break'
140140
self.cli_args, restart = run_args if customize else ([], True)
141141
interp = self.shell.interp
142+
if self.shell.executing and not restart:
143+
# Cannot run without restarting the busy shell (gh-82183).
144+
interp.display_executing_dialog()
145+
return 'break'
142146
if pyshell.use_subprocess and restart:
143147
interp.restart_subprocess(
144148
with_cwd=False, filename=filename)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When the shell is busy running code, using "Run... Customized" with "Restart
2+
shell" unchecked now reports that the shell is executing instead of
3+
restarting it anyway.

0 commit comments

Comments
 (0)