In VS Code, how can I run the active python file in active terminal while running another python script?

huangapple go评论75阅读模式
英文:

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:

  1. "The only way I can run that new script in a new terminal is writing the command in the terminal which is inconvenient."
  2. "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."
  3. "One of them is a long-run script which is currently running."
  4. "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."
  5. "Another script is a new script which is in development mode, so I need to run it multiple times."
  6. "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."
  7. "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-notebookpython交互窗口

您可以在不同的.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 &amp;

More details: how-to-run-linux-commands-in-background

huangapple
  • 本文由 发表于 2023年4月17日 06:32:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定