microsoft / microsoft/vscode-python-debugger
Prevent vscode from exiting the Python interpreter a script completes
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 181
- 派生
- 126
- 平均合并
- 2 天 3 小时
- 30 天内合并 PR
- 3
描述
Discussed in https://github.com/microsoft/vscode-python/discussions/16082
Originally posted by larsoner April 29, 2021
The way I have used Python for years (through Spyder, directly from a bash terminal, etc.) is to execute a script in interactive mode such that once it's done, you can interact with it, e.g.:
python -i script.py
VSCode's debugger does not give a way to get this behavior currently. And it seems like I am not the only one looking for it:
- https://stackoverflow.com/questions/56568304/how-to-run-my-python-module-in-visual-studio-code-in-interactive-mode
- https://stackoverflow.com/questions/54609806/how-to-prevent-vscode-from-exiting-python-environment-after-running-code
- https://www.reddit.com/r/vscode/comments/8uv8xc/how_to_keep_python_running_after_script_execution/
- https://github.com/microsoft/vscode-python/issues/5497
One workaround is to put a breakpoint at the end of your file, but this requires extra work.
Another workaround is to add "env": {"PYTHONINSPECT": "true"}, to the launch configuration with integratedTerminal, but this doesn't work properly as any input is captured and newlines aren't treated properly while printing, which makes it pretty unusable.
I could see at least two potential solutions (the first would be better I think):
- Make it so that in
PYTHONINSPECTmode, the terminal could be interacted with properly, possibly by adding a newinspectOnExitor something that ran in-i/PYTHONINSPECTmode and returned proper input/output when the script completes. Based on https://github.com/microsoft/vscode-python/issues/5497 it sounds like this is a no-go, though. - Add a
stopOnExitdebug option to mirrorstopOnEntryin the debugger. This way at least variables could be inspected using the vscode debugger.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
Issue 中没有指定实现文件或测试。首先查看链接的讨论以及现有的 stopOnEntry 调试器行为,然后将提议的交互式 PYTHONINSPECT 和 stopOnExit 方案与 issue 5497 进行比较。Done 应提供可用的脚本结束后检查体验,而不要求在末尾设置 breakpoint。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100