python / python/cpython

`webbrowser.open` hangs indefinitely when exiting browser defined in `BROWSER` environment variable

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

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
36k
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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

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