14

Every time I close VSCode (after running some Python script) I have a Python task that lingers in my terminal running 90-100% CPU on my M1 MacBook Air, and I have to manually kill it every time. I ran the following on the PID:

ps aux | grep <PID>

and it returns the same thing every time...

Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python /Users/<user>/.vscode/extensions/ms-python.python-2021.2.625869727/pythonFiles/runJediLanguageServer.py

I checked my VSCode extensions, and I don't have any "Jedi" ones installed, but maybe it's a lingering task from some other extension. Any ideas how to fix this?

2
  • 1
    There's an open github issue about this with a fix: github.com/microsoft/vscode-python/issues/15586
    – Hebo
    Mar 30, 2021 at 8:14
  • @Hebo Great, thank you! I had gotten so used to running killall Python after every session. I will give this a shot :)
    – JD2775
    Mar 30, 2021 at 15:01

3 Answers 3

10

The solution as provided in the link Valy provided above is to:

  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"]
  4. Reload the window (either by closing VS Code and opening it again or running the "Developer: Reload Window" command from the command palette)

reference: Rogue Python Processes with High CPU Consumption issue #15586

4

I had the same issue as apparently VSC is experimenting with a new feature. Another user helped me find the solution, which can be found here: https://github.com/microsoft/vscode-python/issues/15586#issuecomment-792360066

1
  • 2
    You could detail the fix here too
    – kheraud
    Apr 14, 2021 at 9:48
2

When using python in VS Code, it requires us to install the "python" extension, and it will automatically load the corresponding language service to better identify and analyze the code.

"Visual Studio Code provides smart editing features for different programming languages through Language Extensions. VS Code doesn't provide built-in language support but offers a set of APIs that enable rich language features."

We can use different python language services: Jedi, Microsoft, Pylance, and so on, and VS Code uses Jedi by default:

enter image description here

enter image description here

Reference:Language Server Extension Guide and Language Extensions Overview.

4
  • 1
    thanks, that makes sense, but how do I prevent these tasks from continuing long after VSCode has been closed? Currently I am doing: killall Python in my terminal after I am finished, not the most efficient way to handle it I am sure but it does the job for now
    – JD2775
    Mar 8, 2021 at 15:34
  • @JD2775 -You could try to set the language service as "python.languageServer": "None", before closing VS Code, and then reload VS Code.
    – Jill Cheng
    Mar 9, 2021 at 1:25
  • 1
    Thanks Jill. Unfortunately that doesn't help. It is pretty annoying. If I open VSCode, run "hello world" and close VS Code (and repeat that 5 times) I end up with 5 Python (Jedi language) tasks still running in the background even after all sessions are closed, all using 80-90% CPU. Guess Ill just live with the killall Python command workaround that I've been using
    – JD2775
    Mar 9, 2021 at 17:11
  • Same here, using ubuntu 20.04. Had to uninstall the python extension for the time being in order to keep this annoying behavior. Apr 2, 2021 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.