vscode-python: Rogue Python Processes with High CPU Consumption

Opening python (.py) files in Visual Studio Code (VSC) resulted in rogue python3.8 processes that did not terminate after closing the files or quitting VSC. The processes consumed over 81% of the CPU and were associated with rapid loss of battery power on a MacBook Air (M1, 2020). This was repeatable with an empty file with a .py extension.

Steps to Reproduce the Problem

. Started VSC without any installed extensions. . Opened existing emptyfile.py file with no content. . No python3.8 processes running. . Closed emptyfile.py file. . Closed VSC window. . Quit VSC. . No python3.8 processes running. . Opened VSC. . Installed Python extension. This also installed jupyter extension. . No python3.8 processes running. . Opened emptyfile.py file. . Checked for python processes:

% ps -ax | grep python
 4286 ??         0:00.27 /Users/Scott/anaconda3/bin/python /Users/Scott/.vscode/extensions/ms-python.python-2021.2.625869727/pythonFiles/runJediLanguageServer.py
 4299 ??         0:00.15 /Users/Scott/anaconda3/bin/python /Users/Scott/anaconda3/lib/python3.8/site-packages/jedi/inference/compiled/subprocess/__main__.py /Users/Scott/anaconda3/lib/python3.8/site-packages 3.8.5 

. CPU use around 5%

. Closed emptyfile.py file. . The two processes from ps above still present. . Closed VSC window. . python3.8 processes, PID 4286, now using about 81% CPU. . Quit VSC. . python3.8 processes, PID 4286, still using about 81% CPU. . Process, PID 4289, from above ps still running. . kill 4286 from terminal. . Processes, PIDs 4286 and 4299, from above ps, no longer present. . CPU use back down to around 6%.

Configuration

Visual Studio Code Version: 1.54.1 Commit: f30a9b73e8ffc278e71575118b6bf568f04587c8 Date: 2021-03-04T22:42:18.719Z (19 hrs ago) Electron: 11.3.0 Chrome: 87.0.4280.141 Node.js: 12.18.3 V8: 8.7.220.31-electron.0 OS: Darwin x64 20.3.0

Model Name: MacBook Air Model Identifier: MacBookAir10,1 Chip: Apple M1 Memory: 16 GB System Firmware Version: 6723.81.1

System Software Overview: System Version: macOS 11.2.2 (20D80) Kernel Version: Darwin 20.3.0

Python 3.8.5

VSC Extensions

Python ms-python.python v2021.2.625869727

Jupyter ms-toolsai.jupyter Microsoft 10,388,239 Repository License v2021.3.619093157

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 16
  • Comments: 55 (25 by maintainers)

Most upvoted comments

Thanks for giving this info! I think the problem may be one of our new features, can you try disabling it by following the steps below, and see if that fixes the problem you’re experiencing?

  1. Open the command palette (View > Command Palette…)
  2. Run the “Preferences: Open Settings (JSON)” command. This will open the user settings in VS code
  3. Paste the following line in the settings file:
"python.experiments.optOutFrom": ["pythonJediLSP"]
  1. Reload the window (either by closing VS Code and opening it again or running the “Developer: Reload Window” command from the command palette)

The problem no longer occurs after following the steps outlined by luabud, which added
“python.experiments.optOutFrom”: [“pythonJediLSP”], to settings.json.

@mmattbtw there is fix for this is in insiders.

Looks like jedi-language-server updated to take a newer dependency on psutil which requires shipping wheels for every OS (we build using Linux, hence the macOS wheels aren’t going out). We are working on a fix.

I was seeing this, only over Remote-SSH. I.e. a ms-python.python-2021.2.582707922/pythonFiles/runJediLanguageServer.py process using over 100% CPU, even after vscode was closed.

I tried switching to PyLance, which didn’t have that problem, but wasn’t giving me functionality I’d gotten used to (specifically, greying out of function args that are not being used). So I tried uninstalling all the extensions, and re-installing latest versions. Same problem with Jedi. So then I tried changing from “Jedi” to “JediLSP”. I now see a ms-python.python-2021.5.842923320/pythonFiles/run-jedi-language-server.py process running, but using less CPU, and it correctly disappears when vscode is closed.

Hope that helps someone.

@finiteautomata Set "python.languageServer": "Pylance". The experiment optout can be set only at machine level.

I’m running vscode through Remote-SSH, and I’m experiencing the same issue of processes consuming a lot of CPU in the remote machine. I tried the "python.experiments.optOutFrom": ["pythonJediLSP"] stuff but the editor puts a warning over it which says

This setting cannot be applied in this window. It will be applied when you open local window.

Any idea of what to do in this case?

For anyone running into this issue. Can you try the insiders version of the python extension? You can get the insiders version here: https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix

That version uses the latest jediLSP language server. If that does not help and is blocking your work, try setting language server as pylance. You may need to install pylance extension from marketplace.

@karthiknadig Thanks! I haven’t experienced the issue again since I update to the insiders channel 😃

@paulo-serrao You can get insiders version of python two ways:

Option 1: Turn on insiders from settings, to either daily or weekly

image

Option 2: Manually install using vsix

Download the vsix from here: https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix Use the install from vsix option from here: image

I’m also experiencing this issue. Even tried rolling back to 2021.2.636928669 but also have the same problem.

It keeps spawning a new one every time I switch to a different project…

27421 ??        13:00.38 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/runJediLanguageServer.py
27426 ??         0:00.24 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python/jedi/inference/compiled/subprocess/__main__.py /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python 3.9.0
29462 ??         3:46.33 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/runJediLanguageServer.py
29481 ??         0:00.30 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python/jedi/inference/compiled/subprocess/__main__.py /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python 3.9.0
29888 ??         1:35.65 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/runJediLanguageServer.py
29908 ??         0:00.49 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python/jedi/inference/compiled/subprocess/__main__.py /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python 3.9.0
30132 ??         0:01.00 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/runJediLanguageServer.py
30133 ??         0:00.20 /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python/jedi/inference/compiled/subprocess/__main__.py /Users/username/.vscode/extensions/ms-python.python-2021.2.636928669/pythonFiles/lib/python 3.9.0

I need to kill them manually…