You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Run Selection/Line in already active python interpreter terminal rather than opening a new terminal #24960
Hi, my workflow setup allows me to work on SLURM allocated resources on an already configured terminal for debugging code.
So when I send code to the terminal, it triggers the opening of a new terminal python interpreter instead of running the code in the already opened terminal.
It will be very useful for me to have run the code on already configured python terminal.
While investigating the behavior of the Run Selection/Line in Python Terminal command in the source code, I found that the existing terminal is reused to execute the selected code only if the terminal was originally opened by the same command.
However, if the terminal was opened manually, a new terminal will be launched instead.
omkarchandra
I'm not sure about the exact details of how you launch the SLURM allocation, but if it's initiated from a VSCode terminal, you can achieve your desired workflow by following these steps:
Open a terminal by running the Run Selection/Line in Python Terminal command (you can use any arbitrary code).
Exit the Python interpreter by running exit().
From the same terminal, perform the necessary steps to launch the SLURM environment.
Start the Python interpreter within the SLURM environment.
Now, use Run Selection/Line in Python Terminal again to run your selected code in the already configured terminal.
However, I believe this behavior is definitely confusing.
It would be better to improve it so that the selected code is executed in the existing terminal, regardless of how the terminal was opened.
Anthony Kim (@anthonykim1)
The current behavior is implemented by the initializeRepl method in the TerminalCodeExecutionProvider class:
public async initializeRepl(resource: Resource) {
const terminalService = this.getTerminalService(resource);
// Case of using the existing terminal
if (this.replActive && (await this.replActive)) {
await terminalService.show();
return;
}
// Case of using a new terminal
...
}
Currently, this.replActive is initialized by the previous “Run Selection/Line” execution.
This means the existing terminal is reused only if it was originally created by the “Run Selection/Line” command.
However, I believe the behavior should follow these rules:
Prefer using an existing terminal (only create a new one if none is available).
If a Python REPL is not active in the selected terminal, it should be initialized.
Then, execute the code in that terminal.
If this approach sounds reasonable, may I go ahead and modify the code and open a PR accordingly?
Thank you for digging into this and suggesting a solution!
Yes, that should be the right behaviour. Please go ahead and open a PR.
This will make my workflow so much smoother. Thank you!
Thanks all for your feedback! Shin Kinoshita (@s-kai273) And Yes absolutely :)
Feel free to give this a try, and you can directly assign me as a reviewer.
Activity
anthonykim1 commentedon Apr 16, 2025
thanks for filing this, this might be a bug or feature request. I would need to take a closer look.
s-kai273 commentedon May 10, 2025
While investigating the behavior of the Run Selection/Line in Python Terminal command in the source code, I found that the existing terminal is reused to execute the selected code only if the terminal was originally opened by the same command.
However, if the terminal was opened manually, a new terminal will be launched instead.
s-kai273 commentedon May 10, 2025
omkarchandra
I'm not sure about the exact details of how you launch the SLURM allocation, but if it's initiated from a VSCode terminal, you can achieve your desired workflow by following these steps:
Open a terminal by running the Run Selection/Line in Python Terminal command (you can use any arbitrary code).
Exit the Python interpreter by running exit().
From the same terminal, perform the necessary steps to launch the SLURM environment.
Start the Python interpreter within the SLURM environment.
Now, use Run Selection/Line in Python Terminal again to run your selected code in the already configured terminal.
I hope these tips would help you.
s-kai273 commentedon May 10, 2025
However, I believe this behavior is definitely confusing.
It would be better to improve it so that the selected code is executed in the existing terminal, regardless of how the terminal was opened.
omkarchandra commentedon May 16, 2025
Yes, thank you for the workaround recommendation.
I wish a patch-up would be done to correct this behavior.
s-kai273 commentedon May 17, 2025
Anthony Kim (@anthonykim1)
The current behavior is implemented by the
initializeReplmethod in theTerminalCodeExecutionProviderclass:Currently,
this.replActiveis initialized by the previous “Run Selection/Line” execution.This means the existing terminal is reused only if it was originally created by the “Run Selection/Line” command.
However, I believe the behavior should follow these rules:
If this approach sounds reasonable, may I go ahead and modify the code and open a PR accordingly?
omkarchandra commentedon May 17, 2025
Thank you for digging into this and suggesting a solution!
Yes, that should be the right behaviour. Please go ahead and open a PR.
This will make my workflow so much smoother. Thank you!
anthonykim1 commentedon Jun 10, 2025
Thanks all for your feedback!
Shin Kinoshita (@s-kai273) And Yes absolutely :)
Feel free to give this a try, and you can directly assign me as a reviewer.
s-kai273 commentedon Jun 10, 2025
Anthony Kim (@anthonykim1)
OK, thank you!
I'll try it.
s-kai273 commentedon Jun 13, 2025
Anthony Kim (@anthonykim1)
Hi, I roughly implemented this feature on #25178.
Please review it, thanks!