Skip to content

Jedi: overlapping language server restarts leak Jedi processes and completion hangs #26296

Open

Description

@AndreasReichel

Type: Bug

Behaviour

With Jedi as language server (python.languageServer: "Jedi", or "Default" without Pylance), changing the
active interpreter and restarting the language server in quick succession leaves extra
run-jedi-language-server.py processes running. Completion in Python files then hangs (the suggest widget
stays at "Loading..." / no results) until the window is reloaded.

Each interpreter change stops the Jedi server and starts a new one with the new interpreter. When the next
stop or restart arrives while a start is still in progress, the server that is being started is not stopped
and stays running without being connected/tracked.

A related symptom: when python.analysis.restartLanguageServer runs before the extension has started Jedi
for the first time (e.g. while it is still resolving the interpreter at startup), it starts a server that is
never connected. Completion then shows nothing in the whole window until a reload.

Also, the Jedi handler of python.analysis.restartLanguageServer does not return the restart promise, so
await vscode.commands.executeCommand('python.analysis.restartLanguageServer') resolves immediately. Callers
therefore cannot wait for the restart to finish to avoid overlapping it.

Expected

  • At any time at most one Jedi server process per workspace folder, regardless of how quickly interpreter
    changes and restarts follow each other (a pending start is cancelled/stopped, or requests are serialized).
  • python.analysis.restartLanguageServer resolves after the new server is running, as with Pylance.

Actual

  • After "switch away, switch back, restart" sequences, more than one run-jedi-language-server.py process
    runs for one workspace folder (expected: 1).
  • Completion hangs until Developer: Reload Window.

Steps to reproduce

  1. Settings: "python.languageServer": "Jedi". Workspace with a virtual environment .venv and at least one
    other interpreter available (e.g. a global Python).

  2. Open a .py file and wait until completion works.

  3. Run the following sequence of calls from an extension. We hit this through our own extension, which
    switches the interpreter away and back so that language servers pick up changed .pth files; the snippet
    shows the calls it makes (it waits up to 1 s between the two switches until the venv's python.exe is
    released):

    import { PythonExtension } from '@vscode/python-extension';
    
    const api = await PythonExtension.api();
    const folder = vscode.workspace.workspaceFolders![0];
    await api.environments.updateActiveEnvironmentPath(otherPythonPath, folder);
    await api.environments.updateActiveEnvironmentPath(venvPythonPath, folder);
    await vscode.commands.executeCommand('python.analysis.restartLanguageServer');

    Doing the same by hand (Python: Select Interpreter twice quickly, then Python: Restart Language Server)
    may also work, but is timing dependent.

  4. Count the Jedi processes (Windows PowerShell):

    Get-CimInstance Win32_Process -Filter "Name='python.exe'" |
      Where-Object CommandLine -match 'run-jedi-language-server' |
      Select-Object ProcessId, CommandLine
  5. Try completion in the open .py file.

Diagnostic data

  • Python extension version: 2026.10.0 (ms-python.python-2026.10.0-win32-x64)
  • Python Environments extension: 1.42.0
  • VS Code version: 1.127.0 (4fe60c8b1cdac1c4c174f2fb180d0d758272d713), x64
  • OS: Windows 11 Enterprise 10.0.22631
  • Language server: Jedi (Pylance not installed / python.languageServer: "Jedi")
  • Python version: 3.14.5

Notes

We have only seen this with Jedi. Pylance does not run inside the selected interpreter, so an interpreter
change does not replace its process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions