Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Lib/idlelib/idle_test/test_runscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from idlelib import runscript
import unittest
from unittest import mock
from test.support import requires
from tkinter import Tk
from idlelib.editor import EditorWindow
Expand All @@ -28,6 +29,26 @@ def test_init(self):
sb = runscript.ScriptBinding(ew)
ew._close()

def test_run_module_event_shell_busy_no_restart(self):
# gh-82183: running without restarting the busy shell aborts.
ew = EditorWindow(root=self.root)
sb = runscript.ScriptBinding(ew)
sb.getfilename = mock.Mock(return_value='test.py')
sb.checksyntax = mock.Mock(return_value='code')
sb.tabnanny = mock.Mock(return_value=True)
sb.shell = shell = mock.Mock()
shell.executing = True
interp = shell.interp
with mock.patch.object(runscript, 'CustomRun') as customrun:
# Restart shell unchecked.
customrun.return_value.result = (['arg'], False)
result = sb.run_module_event(None, customize=True)
self.assertEqual(result, 'break')
interp.display_executing_dialog.assert_called_once()
interp.restart_subprocess.assert_not_called()
interp.runcode.assert_not_called()
ew._close()


if __name__ == '__main__':
unittest.main(verbosity=2)
4 changes: 4 additions & 0 deletions Lib/idlelib/runscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def run_module_event(self, event, *, customize=False):
return 'break'
self.cli_args, restart = run_args if customize else ([], True)
interp = self.shell.interp
if self.shell.executing and not restart:
# Cannot run without restarting the busy shell (gh-82183).
interp.display_executing_dialog()
return 'break'
if pyshell.use_subprocess and restart:
interp.restart_subprocess(
with_cwd=False, filename=filename)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When the shell is busy running code, using "Run... Customized" with "Restart
shell" unchecked now reports that the shell is executing instead of
restarting it anyway.
Loading