Skip to content

Debugging with shortly-lived subprocesses gives 'Server disconnected unexpectedly' #1912

@bbartyzel

Description

@bbartyzel

VSCode shows an error when a subprocess in a program under debug exits very fast and the subProcess: true is defined in launch.json.

Image

The problem disappears when subProcess: false is set.
Reproduced on two different machines (W11+WSL)

When running the debugger via Powershell on Windows the problem is not reproducible. Only W11+WSL.

Environment data

  • debugpy version: v2025.8.0
  • OS and version: Windows 11 + Debian GNU/Linux 12 (bookworm) (WSL2) [Remote host]
  • Python version: 3.11.2
  • Using VS Code: 1.101.0

Actual behavior

When debugging a python program that spawns a subprocess that exits too quickly this error is shown:

Image

It happens randomly and is possibly related to the subprocess exiting while the debugger is being attached.

Expected behavior

Error does not pop up and the debugger handles such case gracefully.

Steps to reproduce:

  1. Run code that spawns another python subprocess - for example with a module that doesn't exist
import subprocess

def main():
    cmd = "python3 -m idontexist"
    for i in range(0, 20):
        process = subprocess.Popen(cmd.split())
        process.wait()

if __name__ == "__main__":
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reproIssue has not been reproduced yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions