Skip to content

Fix premature pytest debug session exit when multiprocessing child process terminates#1023

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/debug-pytest-exit-issue
Draft

Fix premature pytest debug session exit when multiprocessing child process terminates#1023
Copilot wants to merge 3 commits intomainfrom
copilot/debug-pytest-exit-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

When debugging a pytest test that uses multiprocessing.Process, the debug session exits prematurely as soon as process.join() returns — the test body never completes.

Root Cause

debugpy's notify_of_subprocess copies the parent session's full config to the child process session, including purpose: ['debug-test']. The Python extension's test adapter treats any debug-test session termination as the end of the test run. When the child process exits and its debug session ends, the adapter disconnects the parent (pytest) session.

Changes

  • ChildProcessAttachService.attach() — shallow-copy data before forwarding to debug.startDebugging() and delete purpose from the copy, so the child process session is never tagged as a test session:
const debugConfig: AttachRequestArguments & DebugConfiguration = { ...data };
delete debugConfig.purpose;
  • childProcessAttachService.unit.test.ts — adds two regression tests: one verifying purpose is stripped from the child session config, one verifying the original data object is not mutated.

  • src/test/pythonFiles/debugging/test_multiproc.py — pytest test file reproducing the multiprocessing join issue, for use as a manual/future integration regression test.

  • src/test/pythonFiles/debugging/wait_for_file.py and src/test/.vscode/launch.json — missing infrastructure required by the existing adapter integration test suite.

Copilot AI changed the title [WIP] Fix premature exit in pytest debugger on process.join() Fix premature pytest debug session exit when multiprocessing child process terminates May 6, 2026
Copilot finished work on behalf of rchiodo May 6, 2026 15:35
Copilot AI requested a review from rchiodo May 6, 2026 15:35
@rchiodo
Copy link
Copy Markdown
Contributor

rchiodo commented May 6, 2026

@copilot, there's a weird error when running the CI tests on windows:

Run pipx run nox --session install_bundled_libs
Found a space in the pipx home path. We heavily discourage this, due to
multiple incompatibilities. Please check our docs for more information on
this, as well as some pointers on how to migrate to a different home path.
To see your PIPX_HOME dir: pipx environment --value PIPX_HOME
Most likely fix on macOS: mv ~/Library/Application\ Support/pipx ~/.local/
creating virtual environment...
installing nox...
Fatal error from pip prevented installation. Full pip output in file:
C:\Program Files (x86)\pipx\logs\cmd_2026-05-06_16.33.19_pip_errors.log

Some possibly relevant errors from pip install:
TypeError: dataclass() got an unexpected keyword argument 'slots'
Error installing nox.
Error: Process completed with exit code 1.

I think our nox bundled libs needs to be fixed/updated?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 6, 2026

@copilot, there's a weird error when running the CI tests on windows:

Run pipx run nox --session install_bundled_libs
...

Fixed in 77d393e.

Root cause: pip 26.1+ requires Python ≥ 3.10 (it uses @dataclass(slots=True) internally). The workflow step python -m pip install -U pip pipx wheel was upgrading pip to 26.1 on a Python 3.9 environment, and the upgraded pip then crashed with TypeError: dataclass() got an unexpected keyword argument 'slots' when pipx tried to use it to install nox.

The fix bumps the minimum Python from 3.9 → 3.10 in all three CI files (build-vsix/action.yml, pr-check.yml, push-check.yml), which also aligns with noxfile.py's SUPPORTED_DEBUGPY_CPYTHONS (which already starts at cp310 — Python 3.9 is no longer supported by the bundled debugpy). Python '3.9' has also been removed from the test matrix.

Copilot finished work on behalf of rchiodo May 6, 2026 16:59
Copilot AI requested a review from rchiodo May 6, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debugging pytest tests causes premature exit upon process.join()

2 participants