https://github.com/python/cpython/commit/9e76aa30eef352f514c745b2eb85131181a32c49
commit: 9e76aa30eef352f514c745b2eb85131181a32c49
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: terryjreedy <[email protected]>
date: 2026-09-16T17:51:57-04:00
summary:

[3.14] gh-68453: Fix IDLE -s together with -c, -r or - (GH-157592) (#157641)

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 <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>

files:
A Misc/NEWS.d/next/IDLE/2026-09-15-21-20-04.gh-issue-68453.hlxbog.rst
M Lib/idlelib/pyshell.py

diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index 51568d2a9e950e..b69a5980bc5338 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -1675,6 +1675,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 00000000000000..4d8cfc1dbc6574
--- /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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to