`webbrowser.open` hangs indefinitely when exiting browser defined in `BROWSER` environment variable
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
To reproduce
On my system, I have set the BROWSER environment variable to suggest a preferred browser for console applications to use.
# my .zshrc
# Use Firefox Dev Edition as my preferred browser if it's on the path
if command -pv firefox-aurora &> /dev/null; then
export BROWSER='firefox-aurora'
elif command -pv firefox &> /dev/null; then
export BROWSER='firefox'
fi
As a consequence, calls to webbrowser.open launch Firefox Deverloper Edition (firefox-aurora), which is correct. However, if an instance of firefox-aurora isn't already running, my script will freeze until firefox-aurora exits entirely.
import webbrowser
webbrowser.open('https://example.com')
print('Done')
Additionally, interrupting my script using Ctrl+C causes the browser to crash, likely due to a SIGHUP.
This causes significant issues for my script, as I wish to open multiple sites at once.
Suggested fix
The browser defined by the BROWSER variable should be disowned by the webbrowser , perhaps by making it a UnixBrowser rather than a GenericBrowser. This does risk breaking terminal-based browsers, so I wonder if there's a way to determine if the browser is terminal-based so that we can tell whether to p.wait() or not.
Otherwise, do you believe this may be an issue with Firefox instead, in that they should launch and detach a new process, allowing the process launched through Python to exit immediately?
One more possibility is that the BROWSER variable is intended for terminal-based browsers, similarly to the EDITOR variable for terminal editors and the VISUAL variable for graphical editors.
CPython versions tested on:
3.12
Operating systems tested on:
Linux (specifically, Fedora 40)
Linked PRs
- gh-149255
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先查看連結的 PR gh-149255,接著檢查 webbrowser.open 進入點及其對 BROWSER 環境變數的處理。在已設定 Firefox 的 Linux 上重現提供的指令碼,並在啟動已設定的瀏覽器後能立即返回,且 Ctrl+C 不會使其當機,同時為終端機瀏覽器提供適當的覆蓋時,將該 issue 視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- desktop-dev
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100