Pausing or adding new breakpoints halfway during running in VSCode makes the Python Exception lost
还没有人认领这个 Issue。
评估
调研方向
首先运行最小 Python 示例,并复现 VSCode 的三个流程:Pause、预先设置的断点,以及运行期间添加断点。比较产生的异常处理,尤其是 sys.settrace 回调消息;当 Pause 和运行期间添加的断点能够像预先设置的断点一样捕获 RuntimeError,且不会让程序停在暂停状态时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Environment data
- debugpy version: 1.8.13
- OS and version:
Linux abc 5.15.0-139-generic #149 ~20.04.1-Ubuntu SMP Wed Apr 16 08:29:56 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux - Python version (& distribution if applicable, e.g. Anaconda): Python 3.10.18 (miniconda 23.5.2)
- Using VS Code or Visual Studio: VSCode
Actual behavior
Pausing or adding new breakpoints halfway during debugging in VSCode seems to make the Python Exception uncaught.
The following is a minimal example to reproduce my problem.
import contextlib, signal
@contextlib.contextmanager
def time_limit(seconds):
def signal_handler(signum, frame):
raise RuntimeError("Timed out!")
signal.setitimer(signal.ITIMER_REAL, seconds)
signal.signal(signal.SIGALRM, signal_handler)
try:
yield
finally:
signal.setitimer(signal.ITIMER_REAL, 0)
if __name__ == "__main__":
print("start")
try:
with time_limit(10):
a=1
while True:
a = -a
except RuntimeError:
print("timed out")
print("finished")
Different ways of debugging will give different results:
-
Use Pause. The exception is not caught. I click the
pause (F6)halfway through running, and the program pauses on the linea=-aas expected. After several seconds, the time limit is reached, and the RuntimeError is thrown, but the program fails to catch the error. The trackback is printed in the console, but the program is not interrupted (still paused). As a result, the program will run forever after clickingcontinue (F5). -
Use preset breakpoint. The exception is caught. In contrast, if you set a breakpoint at the
a=-a. Run the program, and the program will stop at the breakpoint. Wait a few seconds, and the program will catch the runtime error and finish successfully. The program will continue automatically once it receives the Exception without the user's permission, which is also strange to me. -
Add a breakpoint halfway. The exception is not caught. If you add a new breakpoint at
a=-aafter the program runs for a while, you can find the same behavior as "using Pause". In my opinion, "Pause" may be implemented by "adding a breakpoint halfway"? If this is correct, then this problem may be about "adding a breakpoint while running".
More experimental results:
When using Pause. After pausing, if I switch to the Debug Console, the following message will be thrown when the time limit is reached:
<class 'RuntimeError'> raised from within the callback set in sys.settrace.
Debugging will be disabled for this thread (<_MainThread(MainThread, started 140324903388352)>).
Expected behavior
I expect both 1(Use Pause) and 3(Add a breakpoint halfway) to behave similarly to 2(Use preset breakpoint).
Steps to reproduce:
- As stated in Actual behavior, just try to debug the code in three different ways.
- 主要语言
- Python
- 星标
- 2.5k
- 派生
- 205
- 平均合并
- 1 天 43 分钟
- 30 天内合并 PR
- 6
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/debugpy 的其他 Issue
-
pydevd_comm.py start_client() does not set TCP_NODELAY on the connections it opens可能已有人在做 @nightcityblade 于 55 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
Document "rules"-option可能已有人在做 @nightcityblade 于 43 天前认领。 未关闭documentation
难度 2/5 1-3 小时 新手友好度 68/100
-
wx.EventLoop() deprecation warning可能已有人在做 @nightcityblade 于 42 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
debugpy.configure(python=) is not properly documented可能已有人在做 @nightcityblade 于 53 天前认领。 未关闭documentation
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 5/5 一周以上 新手友好度 15/100
查看 microsoft/debugpy 的全部 Issue
相似的 Issue
-
Performance: deprecated DeviceEntry.config_entries access blocks the event loop for tens of seconds未关闭
难度 2/5 1-3 小时 新手友好度 75/100
tuya/tuya_cloud_ha_bridge#14 ·
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
semantica-agi/semantica#1968 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
agent: ready area: submission priority: high type: docs
难度 2/5 1-3 小时 新手友好度 62/100
dkritarth/scopewatch#213 ·
维护者通常 1 天内回复
-
Broken link in RELEASE.md可能已有人在做 @Jah-yee 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
sphinx-contrib/httpdomain#143 ·
维护者通常 1 天内回复