Run Python File: Long delay before command line appears in terminal after terminal window opens #26003
Replies: 1 comment
-
|
This is a known interaction between VS Code's terminal Shell Integration feature and the Python extension's run/activate flow, not something specific to your setup. What's happening is when you click "Run Python File" (or open a new terminal with auto-activation), the extension sends the run/activation command to the terminal using sendText. With shell integration enabled, VS Code waits for the shell to emit its integration handshake sequences (the OSC 633 markers that let VS Code track command start/end, exit codes, etc.) before it considers the terminal ready to receive that command. On some shell/prompt configurations, that handshake itself is slow, so the actual python file.py (or source .venv/bin/activate) line sits buffered for a few seconds even though the terminal looks fully open. This has been reported and confirmed by the VS Code Python team in several issues: #24239 -> same symptom (run button delayed, F5/Ctrl+F5 unaffected); team confirmed it was shell-integration-related (karthiknadig: "This looks like Shell integration taking too long") and shipped a partial fix in extension v2024.16.1. #25435 and the earlier #15719 -> describe the same late-arriving-command behavior for venv activation specifically, sometimes severely enough that typed input gets mixed in with the activation command. What you did (disabling terminal.integrated.shellIntegration.enabled) is the documented and currently the most reliable workaround, since it makes the extension fall back to sending text immediately without waiting on the handshake. Trade off to be aware of is disabling shell integration globally also turns off other terminal features that depend on it - command decorations, sticky scroll for commands, "Run Recent Command", and inline error/exit-code detection in the terminal. Updating to the latest Python and Python Environments extension versions (this regressed and got partially fixed multiple times across releases, so which version you're on matters). Switching python-envs.terminal.autoActivationType to shellStartup instead of the default command-based activation (see vscode-python-environments#226) - this activates the venv via your shell's startup script instead of an injected command, sidestepping the handshake delay entirely. Could you share your exact Python extension version and shell (bash/zsh/fish/etc.)? That'll tell us whether you're hitting the original #24239 regression or a newer one, since this keeps resurfacing in different extension versions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
who can help me?
It took a long time to run my code when I pressed the "Run Python File" button. This problem applies to every Python file I try to execute (no matter how long the file is or where the file is in). The time that the terminal is opened and the execution time itself is the same as before, but it takes a few seconds until the one-line command (path of python intepreter) "(path of python file)" appears after the terminal window appears.
When I open VSCode, the speed at which it automatically opens a terminal with the venv activated is normal,But when I manually start a new terminal, it also takes a few seconds before executing the environment activation command, the status bar's "[Activating venv environment]" is spinning.
The version a few months ago was fine.
When I disable
terminal.integrated.shellIntegration.enabled, the speed is normal.Beta Was this translation helpful? Give feedback.
All reactions