Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Script subprocesses cannot be debugged

Open
#1,929 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
devtools

Research direction

Start in src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py, especially is_python and patch_args, and inspect their callers. Reproduce the issue with a launcher using subprocess.run to invoke a shebang script directly, then verify that a breakpoint in the shebang script is reached when the subprocess arguments are patched.

Written by the indexing model from the issue text.

Description

bug

Currently, if a python script is executed directly as a subprocess by using a shebang, it isn't debugged.

This is clear from the code which is currently only checking the executable name for python and family.

https://github.com/microsoft/debugpy/blob/ea1dd9a838749a58bcc2d026693cc5a3c3cdbad1/src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py#L283

Looking at pydevd logs, it exits with "Process is not python, returning." as expected from the code.

https://github.com/microsoft/debugpy/blob/ea1dd9a838749a58bcc2d026693cc5a3c3cdbad1/src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py#L394

Not simple, but IIUC fixing this means that it should open the file, check for a shebang, and replace the executable with the shebang line + script location. I'm uncertain if only patch_args needs to be updated with such logic or every caller of is_python.

Note I don't create the script myself but use project.scripts, and uv_build compiles the script wrapper when running uv sync. A manually shebanged file would naturally have the same issue though is easier for the user to replace with a python invocation - with a project.scripts, there is some awkwardness with it being in the .venv/bin directory, not cwd (I am using a multi-project workspace). As a workaround, I will probably still resolve the absolute path of the script and prepend python.

Environment data

Skipping since it's obvious from the code

Actual behavior

debugpy does not patch the subprocess args for a python script, causing debug to fail

Expected behavior

A python script subprocess can be debugged

Steps to reproduce:

  1. Create a python script with a shebang
  2. Create another script that invokes the script directly with subprocess.run, without python
  3. Debug the launcher script with a breakpoint in the shebang script

My shebang script for a django project created by uv looks like

manage

#!/Users/anuraag/git/workspace/.venv/bin/python3
# -*- coding: utf-8 -*-
import sys
from sysadmin.manage import main
if __name__ == "__main__":
    if sys.argv[0].endswith("-script.pyw"):
        sys.argv[0] = sys.argv[0][:-11]
    elif sys.argv[0].endswith(".exe"):
        sys.argv[0] = sys.argv[0][:-4]
    sys.exit(main())
Dominant language
Python
Stars
2.5k
Forks
202
Avg merge
5d 1h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/debugpy

All issues in microsoft/debugpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.