From 5968ae9e9e5f1db6963e90a5a4ad849d48a8dca3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 16 Sep 2026 00:20:04 +0300 Subject: [PATCH] gh-68453: Fix IDLE -s together with -c, -r or - 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. 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 6e57e306a3678d9..4965c14fd2a4ced 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -1674,6 +1674,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.