英文:
In VS Code, how can I run the active python file in active terminal while running another python script?
问题
I have couple of scripts I need to run simultaneously. One of them is a long-run script which is currently running and another script is a new script which is in development mode so I need to run it multiple times but I want to do this using "Shift+Enter" keys for convenience.
Currently, when I hit "Shift+Enter", I get switched to the previous terminal where the long-run script is running and nothing happens after, however I have already created a new terminal window and activated the new environment in which I am developing the new script... The only way I can run that new script in a new terminal is writing the command in the terminal which is inconvenient and takes more time than just hitting "Shift+Enter". Could someone help me with that?
英文:
I have couple of scripts I need to run simultaneously. One of them is a long-run script which is currently running and another script is a new script which is in development mode so I need to run it multiple times but I want to do this using <kbd>Shift+Enter</kbd> keys for convenience.
Currently, when I hit <kbd>Shift+Enter</kbd>, I get switched to the previous terminal where the long-run script is running and nothing happens after, however I have already created a new terminal window and activated the new environment in which I am developing the new script... The only way I can run that new script in new terminal is writing the command in terminal which is inconvenient and takes more time than just hitting <kbd>Shift+Enter</kbd>. Could someone help me with that?
答案1
得分: 0
Here are the translations:
- "The only way I can run that new script in a new terminal is writing the command in the terminal which is inconvenient."
- "Workaround: Take a look at the 'File: Copy Relative Path of Active File' command and see what keybinding it's bound to. You can use that to copy the relative path and then paste it into your terminal."
- "One of them is a long-run script which is currently running."
- "I'd suggest just running that long-running one in its own terminal. You can have multiple VS Code integrated terminals open at a time. See the '+' button."
- "Another script is a new script which is in development mode, so I need to run it multiple times."
- "Actually, a lot of shells have history features built-in (e.g., Bash's Readline, PowerShell's PSReadLine, etc.). You can probably just press the up and down arrow keys to navigate between previously-run commands in your shell, and then press enter to run one again."
- "For the record, here's my answer to the actual question here: I don't know of any way to get exactly what you're looking for."
英文:
> The only way I can run that new script in new terminal is writing the command in terminal which is inconvenient
Workaround: Take a look at the File: Copy Relative Path of Active File
command and see what keybinding it's bound to. You can use that to copy the relative path and then paste into your terminal.
> One of them is a long-run script which is currently running
I'd suggest just running that long-running one in its own terminal. You can have multiple VS Code integrated terminals open at a time. See the "+" button.
> another script is a new script which is in developement mode so I need to run it multiple times
Actually. a lot of shells have history features built in (Ex. Bash's Readline, PowerShell's PSReadLine, etc.). You can probably just press the up and down arrow keys to navigate between previously-run commands in your shell, and then press enter to run one again.
For the record, here's my answer to the actual question here: I don't know of any way to get exactly what you're looking for.
答案2
得分: 0
一种方法,正如用户提到的,是创建多个终端并使用命令 python filename.py
在每个终端上分别运行您的Python文件。
您也可以尝试使用 jupyter-notebook 或 python交互窗口。
您可以在不同的.ipynb
文件中分别运行所需的Python脚本。
英文:
One way, as user mentioned, is to create multiple terminals and run your Python files separately on each terminal by command python filename.py
.
You can also try to use jupyter-notebook or python interactive window.
You can run the required Python scripts separately in different .ipynb
files.
答案3
得分: 0
For linux or gitbash terminals, you can also run your long running script as a background process in the shell.
python3 myscript.py &;
More details: how-to-run-linux-commands-in-background
英文:
For linux or gitbash terminals, you can also run your long running script as a background process in the shell.
python3 myscript.py &
More details: how-to-run-linux-commands-in-background
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论