python-language-server
python-language-server copied to clipboard
Language Server uses 100% CPU and hangs indefinitely (12+ hours) on large project
Environment data
- VS Code version: 1.41.1
- Extension version (available under the Extensions sidebar): 2020.1.58038
- OS and version: Reproduced on both
Ubuntu 18.04.3 LTSandmacOS 10.15.3 - Python version (& distribution if applicable, e.g. Anaconda): 3.6.9, 3.7.6 and 2.7.17
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): none, venv and virtualenv
- Relevant/affected Python packages and their versions: any
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"set to; more info microsoft/vscode-python#3977): Language Server
Expected behaviour
When opening a Python file, the python language server should start, analyze files, and provide intellisense, navigation, autocomplete and so on.
Actual behaviour
When opening a python file, the language server starts, but does not appear to analyze any files (output log prints a list of search paths, and then nothing else) and sits using 100% CPU usage indefinitely (left running overnight so at least 12 hours of sitting at 100% with no output)
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
- Open a python file. The project is a mixed-language project which I suspect may be causing the issue, it contains a
srcdirectory with several standalone bash and python scripts and then several directories containing C code with the majority of actual python source insidesrc/python/<package name>. The python extension appears to detectsrcas the search path (from the language server output panel) so it might be getting stuck looking over a bunch of non-python files? There appears to be no way to change this behavior, adding src/python topython.autocomplete.extraPathsorPYTHONPATHin.envaddssrc/pythonto the search paths, but does not removesrc.
Logs
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
Python
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'WebHostNotebook - control'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> /usr/local/bin/python -c "import sys;print(sys.executable)"
> conda info --json
> ~/.pyenv/shims/python3.7 ~/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py
> ~/.pyenv/shims/python3.7 ~/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py
> ~/.local/bin/flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/appliance/src/python/<package>/__init__.py
cwd: ~/appliance
Starting Microsoft Python language server.
Python Language Server
[Info - 12:18:07 PM] Analysis cache path: /home/<user>/.cache/Microsoft/Python Language Server
[Info - 12:18:07 PM] Microsoft Python Language Server version 0.5.30.0
[Info - 12:18:07 PM] Workspace root: /home/<user>/appliance
[Info - 12:18:08 PM] GetCurrentSearchPaths /usr/local/bin/python
[Info - 12:18:08 PM] Interpreter search paths:
[Info - 12:18:08 PM] /usr/lib/python3.6
[Info - 12:18:08 PM] /usr/lib/python3.6/lib-dynload
[Info - 12:18:08 PM] /home/<user>/.local/lib/python3.6/site-packages
[Info - 12:18:08 PM] /usr/local/lib/python3.6/dist-packages
[Info - 12:18:08 PM] /usr/lib/python3/dist-packages
[Info - 12:18:08 PM] User search paths:
[Info - 12:18:08 PM] /home/<user>/appliance/src/python
[Info - 12:18:08 PM] /home/<user>/appliance/src
Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)
https://gist.github.com/rainyday/f1602f84b4a87d9de6ebcfff21d31a0c
Unlikely, LS does not look into non-Python files. Most probably circular import references are causing trouble or simply there are a lot of imports. Try getting LS log per https://github.com/microsoft/python-language-server/blob/master/TROUBLESHOOTING.md#filing-an-issue.
Setting python.analysis.logLevel to Trace does not provide any additional output from the python language server.
I see the same problem using a late-2020 version VS Code on a mac, all the deets are below. I use a virtual environment based on Py 3.6. The 100% cpu problem does NOT happen on all folders. Here are my observations.
VS code works as expected (no 100%) CPU when I open a VS code window on a small folder with all good scripts then open a tab with a Python file. "Good" here means all have valid imports -- the packages are in my virtual env.
VS code fails every time (the osx activity monitor shows Microsoft.Python.LanguageServer process at 100% ) if I open a VS code window on a large folder with some bad scripts, then open a tab with a Python file. "Bad" means some scripts have at least one invalid import -- the packages are not in my virtual env. It does not matter what python file I open first - good or broken. Unfortunately this is the source folder for an internal company project so I cannot just zip it up and post it here :(
I don't know if broken files and/or missing imports are the sole cause. Probably not, because I tried creating a bogus-import file in an otherwise pristine folder and that did not trigger the problem.
To get the LanguageServer CPU to stop I have to close the large folder; of course quitting the app entirely works also.
My workaround is to open just a single file at a time, not a folder. Then the blasted CPU & fans stay calm.
Version: 1.52.1
Commit: ea3859d4ba2f3e577a159bc91e3074c5d85c0523
Date: 2020-12-16T16:30:02.420Z (1 mo ago)
Electron: 9.3.5
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Darwin x64 19.6.0
This project is not being actively maintained. You may want to try out Pylance: https://github.com/microsoft/pylance-release
Thanks @jakebailey but please help me understand. Did I post to the wrong GitHub project about this problem? Which VS Code extension is responsible for the process Microsoft.Python.LanguageServer? In my VS Code the only Python extension I have installed is called just "Python" and it's version 2020.12.424452561. That seems to be actively maintained, amiright?
This is the repo for MPLS, which is that process, yes. The Python extension only runs it (but the code does not live there). MPLS still works for many people and the Python extension can still run it, but we aren't actively advertising it as the best option.