Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Script subprocesses cannot be debugged

未关闭
#1,929 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
devtools

调研方向

从 src/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py 开始,重点查看 is_python 和 patch_args,并检查它们的调用方。使用 subprocess.run 直接调用 shebang 脚本的 launcher 重现该问题,然后验证在对 subprocess 参数进行 patch 后,shebang 脚本中的断点能够被命中。

由索引模型根据 Issue 内容生成。

描述

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())
主要语言
Python
星标
2.5k
派生
208
平均合并
1 天 43 分钟
30 天内合并 PR
6

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/debugpy 的其他 Issue

查看 microsoft/debugpy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。