python-language-server
python-language-server copied to clipboard
LS won't close
Environment data
- Language Server version: 0.4.96
- OS and version: Ubuntu 19.04
- Python version (& distribution if applicable, e.g. Anaconda): 2.7.15
Expected behaviour
Language server closes when the vscode exits.
Actual behaviour
Process remains open in the background.
I left vscode open overnight at work with a project open, when I got in this morning the PC was pretty slow, so I ran a htop and noticed that the VIRT memory of the LS process was about 80GB. I closed down the VSCode window to clear the process, but even after closing vscode the LS continued open. Waited a couple of minutes and then killed it in order to start a new one.
Not sure if this should be treated as 2 different issues, the high VIRT memory and the LS not closing down.
Code Snippet / Additional lnformation
LS monitors parent process and normally closes down even if VSC didn't send the shutdown request. So I guess it may be stuck somewhere waiting and does not get time ticks?
I wouldn't worry about the high virtual count. I've seen things like Chrome's NaCl runtime do the same thing. Since we're in .NET, there's technically a runtime which interprets an IL and JITs out some code. It may allocate a big virtual memory arena but then not use it (hence the <1GB actual reserved/in use space). I know there are other open memory issues, but they focus on actual memory usage being high.
On the subject of it not exiting, that's surprising for a few reasons:
- On startup, we monitor the parent process to try and exit when it does.
- The editor can send a notification to us to signal a close.
Yeah, I think I may not have been an issue and simply closing the overnight process was taking a long time and I assumed it wouldn't close itself. I've not been able to reproduce this again so I'm going to close and reopen it if it happens again.
@jakebailey @MikhailArkhipov Found a bit of information on the case when the LS won't close. I'm using the insiders version of the Python Extension and noticed that the current switch between the old version and the new one left a LS process out of date open in the background. Unsure if is an LS or Python extension issue.
If i collapse those 0.4.105 process I notice that there are 2 of them, one with PID of 2487 and 526.
This may be b/c LS didn't get shutdown event (or there is a bug). Host process id probably remained the same so code that tracks host lifetime didn't terminate LS either.
I've noticed something else related to this bug. Doesn't seem to be tied to actually closing the VSCode instance in nature, but is an effect of it. I've resorted to work with the LS with an htop window open and several times I've noticed that when my VirtualMemory shoots up like crazy a second instance of VSCode shows up.
This comes accompanied with general freezing and bad performance of the LS, half parse of words and the autocompletion in general doesn't work. If I reload the VSCode instance, the currently working instance goes away but the one with really high virtual memory sticks around, which is what lead me to believe it was an issue when closing the LS instance.
Just as another datapoint for now, I will try to investigate more:
The LS also does not terminate for me on macOS 10.15.2 even when I quit VSCode; I have to kill the process. I will try to post logs or debug info next time I work on python files, but it seems to happen pretty much every time.
The LS process also consumes 100% of one core and has fairly high memory usage.
I haven't really found any leads from poking around in palantir/python-language-server...
macOS 10.15.2
python-language-server 0.28.2 (I have this globally installed by pip, but VSCode probably installs their own somewhere too?)
Version: 1.41.1
Commit: 26076a4de974ead31f97692a0d32f90d735645c0
Date: 2019-12-18T14:57:51.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 19.2.0
Name: Python
Id: ms-python.python
Version: 2020.1.58038
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python
That's a different language server entirely, and our VS Code extension does not run it.
Looks like Palantir https://github.com/palantir/python-language-server
Sorry, I have both installed but the one that doesn't terminate when VSCode quits is definitely the VSCode one...
It constantly stays above 100% CPU usage even after I quit VSCode.
Here it is after VScode has been quit for about 5 minutes (I am using glances to search for Code or Microsoft to show that VSCode is not running):
Again, not a huge deal—I will try to dig into it and see what is going on, I was just posting this for another data point as reference...
It consistently happens under MacOS (Catalina 10.15.4) for me also. But trying to reproduce it I noticed that it only happens if I try working on a Python notebook in vscode. I.e. if I start vscode and say run my Python unit tests and then exit, then there is no Microsoft.Python.LanguageServer process running subsequently.
However if I do the same thing except subsequently open an ipynb file before exiting vscode, a process for ~/.vscode/extensions/ms-python.python-2020.4.76186/languageServer.0.5.45/Microsoft.Python.LanguageServer continues to run until I kill it.
Here's what the About menu says:
Version: 1.45.0 Commit: d69a79b73808559a91206d73d7717ff5f798f23c Date: 2020-05-07T15:57:33.467Z (4 days ago) Electron: 7.2.4 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Darwin x64 19.4.0
But I believe it's been an issue for me for a while.
This happens specially when there is an update, the old LS sticks around.
This is an issue for me whenever I open a ipynb on MacOS (Catalina).
Just adding some data. I mostly see what others have described here. At the time of this screen, I had been looking to see what was eating my ram/swap. I closed vscode several minutes prior. This is Mojave 10.14.6 and current vscode.
Update - Once I sent a 15 to the process:
I am also seeing Python LanguageServer never closing, however it is not on MacOS but on Linux, through SSH remote (windows client). LS stops as expected when starting VSCode and stopping it shortly afterwards, but it hangs after working for a while (could not identify under which circumstances exactly).
Same here on Windows10::1909. PythonLanguageServer does not stop when I close VScode or close all .ipynb tabs.
Confirm that this exists on Ubuntu 20.04, using VSCode 1.46. Same experience as @fsteinmetz, but also when working locally, not only through SSH remote.
My lumberjack solution to this is to run a very poetic command pkill Microsoft
. Needless to say, this is not a nice thing to write every day.
We haven't had the bandwidth to properly investigate and reproduce this, sorry. The LS is supposed to be watching its parent process to know when to exit, and VS Code is supposed to be sending an exit command if it's exiting cleanly. From the htop screenshots, it appears to be stuck doing something and doesn't get around to that check, but it's hard to tell and I wasn't able to reproduce it the first time around.
If there is a consistent repro, there is a way to attach debugger to the LS process as described here https://github.com/microsoft/python-language-server/blob/master/CONTRIBUTING.md#debugging-c-code-in-microsoft-python-language-server. Perhaps breaking there may reveal where is it stuck.