From 4ff77217a5b7fd048e7e870fa54e138a74535e4d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 16 Sep 2026 22:41:28 +0300 Subject: [PATCH] gh-68453: Fix IDLE -s together with -c, -r or - (GH-157592) The startup file runs in the subprocess asynchronously, so the command or script was queued while it was still executing: an "Already executing" dialog was shown, sys.argv was not set, and the subprocess was restarted, discarding the startup file. Wait for the startup file to finish first. (cherry picked from commit 9cc3547536787ab8375c711ce56601c6b51f0461) Co-authored-by: Serhiy Storchaka Co-authored-by: Claude Opus 5 (1M context) --- Lib/idlelib/pyshell.py | 4 ++++ .../next/IDLE/2026-09-15-21-20-04.gh-issue-68453.hlxbog.rst | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2026-09-15-21-20-04.gh-issue-68453.hlxbog.rst diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index ef3d014d936ce85..3925dfa217193ba 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -1668,6 +1668,10 @@ def main(): if filename and os.path.isfile(filename): shell.interp.execfile(filename) if cmd or script: + # Let the startup file finish first: the command or script + # is to run after it, in its namespace (gh-68453). + while shell.executing: + root.update() shell.interp.runcommand("""if 1: import sys as _sys _sys.argv = {!r} diff --git a/Misc/NEWS.d/next/IDLE/2026-09-15-21-20-04.gh-issue-68453.hlxbog.rst b/Misc/NEWS.d/next/IDLE/2026-09-15-21-20-04.gh-issue-68453.hlxbog.rst new file mode 100644 index 000000000000000..4d8cfc1dbc6574a --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2026-09-15-21-20-04.gh-issue-68453.hlxbog.rst @@ -0,0 +1,3 @@ +Fix running IDLE with the -s option together with -c, -r or -: the command +or script now runs after the startup file, without an error dialog and +without restarting the shell.