Skip to content

Commit 9cc3547

Browse files
gh-68453: Fix IDLE -s together with -c, -r or - (#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. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent eb30805 commit 9cc3547

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎Lib/idlelib/pyshell.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,10 @@ def main():
16751675
if filename and os.path.isfile(filename):
16761676
shell.interp.execfile(filename)
16771677
if cmd or script:
1678+
# Let the startup file finish first: the command or script
1679+
# is to run after it, in its namespace (gh-68453).
1680+
while shell.executing:
1681+
root.update()
16781682
shell.interp.runcommand("""if 1:
16791683
import sys as _sys
16801684
_sys.argv = {!r}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix running IDLE with the -s option together with -c, -r or -: the command
2+
or script now runs after the startup file, without an error dialog and
3+
without restarting the shell.

0 commit comments

Comments
 (0)