python / python/cpython

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

オープン
#125,231 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まずリンクされた PR gh-149255 を確認し、次にエントリーポイント webbrowser.open と BROWSER 環境変数の処理を調べます。Linux 上で Firefox を設定した状態で提供されたスクリプトを再現し、設定したブラウザーの起動がすぐに戻り、Ctrl+C でクラッシュせず、ターミナルブラウザーについても適切なカバレッジがあることを確認できたら、issue は完了とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
desktop-dev
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。