Skip to content

"Run selection in python terminal" sometimes creates a new terminal when one already is being used #18053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
DEVNULLDNE opened this issue Nov 18, 2021 · 6 comments
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug investigating We are looking into the cause of the issue

Comments

@DEVNULLDNE
Copy link

DEVNULLDNE commented Nov 18, 2021

VS Code version

1.62.2

Extension version

v2021.11.1422169775

OS type

Windows

OS version

10

Python distribution

python.org

Python version

3.9.7

Language server

Pylance

Expected behaviour

If there is already a python terminal open, the code will be sent to and run on that terminal.

Actual behaviour

It mostly works as expected. Seemingly randomly it will decide to open a new terminal. If I close this new terminal and try again, it will still open a new terminal. This usually happens after I have not been using the terminal for awhile. Though, the last time this happened it was more like 5 minutes.

I read somewhere that this command basically looks for a terminal named "Python" running python. Creating such a terminal by hand doesn't cause this command to send that terminal the selection though as it will still create a new terminal. It seems like this should be the way it works though so that just changing the name of a terminal will allow you to run code in the terminal of your choosing if you want to run multiple python terminals.

Steps to reproduce

I don't know why it happens. It usually happens after a long period of time but the last time was around 5 minutes.

Here are a list of things I didn't do in those 5 minutes.

  • Create or delete any terminals
  • Do anything related to extensions

Here's a list of things I might have done:

  • Interacted with my web browser
  • Used another vscode window that was also running a python terminal and used the command

I could not reproduce the problem with various ways of interacting with 2 vscode windows each having a python terminal though.

I have noticed this problem for maybe 3 weeks. I don't really know if the behavior is new from when I started using this extension and vscode though which was maybe 3 months ago.

Logs

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@DEVNULLDNE DEVNULLDNE added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Nov 18, 2021
@DEVNULLDNE DEVNULLDNE changed the title Run selection in python terminal creating a new terminal when one already is being used "Run selection in python terminal" sometimes creates a new terminal when one already is being used Nov 18, 2021
@karthiknadig karthiknadig added area-terminal triage and removed triage-needed Needs assignment to the proper sub-team labels Nov 18, 2021
@kimadeline
Copy link

Hi @DEVNULLDNE, thank you for reaching out.

Creating such a terminal by hand doesn't cause this command to send that terminal the selection though as it will still create a new terminal.

When sending a selection to the terminal, the extension will instantiate a terminal, name it "Python", and keeps a reference to it until it's deleted. As long as this terminal is around, the extension will send the selection to it. If it's deleted, the extension will spawn a new one and keep track of it. As such, creating a terminal manually and naming it "Python" won't work, since the extension does not know about it.

I have not being able to reproduce your issue when waiting 5 minutes or more before sending a selection to a terminal. When waiting with VS Code open and an open "Python" terminal, my selection was always sent to the existing "Python" terminal and didn't spawn a new one. I waited 14 and 40 minutes between each selection.

If there is already a python terminal open, the code will be sent to and run on that terminal.

What do you mean here by Python terminal?

@DEVNULLDNE
Copy link
Author

What do you mean here by Python terminal?

The terminal that the command originally creates. It still exists and is perfectly functional but now the command just creates a new terminal instead of using the one it originally created.

It almost never happens quickly, it's usually hours and somehow the reference is gone or bad even though the old terminal still exists. So the command just creates a new terminal and, as far as I can tell, can't be coerced into using the old terminal that is still there. Perhaps some kind of garbage collection? Perhaps I'm running low on ram at some point? I'll see if I can force the problem by overloading my system.

I read somewhere that this command basically looks for a terminal named "Python" running python. Creating such a terminal by hand doesn't cause this command to send that terminal the selection though...

I don't actually do this. I was just suggesting a fix along with different behavior although I should have just said that. So, instead of using a reference, just send the code to a terminal named "Python" preferring the active terminal. Probably too clunky, but this would allow the command to be used on multiple terminals as well.

@kimadeline
Copy link

Perhaps some kind of garbage collection?

Most likely. When you get back to the terminal, do you get a message saying that the session was restored, or something along those lines?

@kimadeline kimadeline added investigating We are looking into the cause of the issue and removed triage labels Nov 19, 2021
@DEVNULLDNE
Copy link
Author

I can reproduce the issue by reloading the vscode window. In the command palette it's "Developer reload window". This definitely was the cause part of the time, but I don't think it was every time; I can't really be sure though. I'm going to just make a feature request that this command be more dynamic with regard to which terminal it applies to. I think this should be the behavior anyway and it would solve this issue if it actually does exist outside of reloading and isn't just the result of some system issue... rent an office in the LHC they said, don't use ECC-RAM they said. Thanks voices in my head.

I'm kidding about the ECC-RAM, who wouldn't use ECC-RAM?

@DEVNULLDNE
Copy link
Author

Oh, I see it's a thing already #15770 . I don't know how to do interlinking or even if I can, but, I think this possible problem is another good reason to rethink this command. I'll put in my 2 cents that the command should prefer the active terminal and if the active terminal isn't named "python", "ipython" or "Python" then it creates a new terminal. "ipython" and "python" because whenever I open python or ipython through the default terminal, the terminal is automatically renamed.

@kimadeline
Copy link

I can reproduce the issue by reloading the vscode window.

When reloading the window, all extensions get shut down and resources get disposed. Even though VS Code will try to restore some of the state that was there before the reload, the Python extension will go through activation again and start in a clean state, hence why it won't remember the previous terminal.

I will close this in favour of #15770 since that would address the root cause of the behaviour you're experiencing, feel free to upvote #15770 and add your feedback there 🙂

Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

3 participants