python / python/cpython

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

Đang mở
#125,231 4 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xem xét PR được liên kết gh-149255, sau đó kiểm tra entry point webbrowser.open và cách xử lý biến môi trường BROWSER. Tái hiện script được cung cấp trên Linux với Firefox đã được cấu hình, và coi issue là hoàn tất khi việc khởi chạy trình duyệt đã cấu hình trả về ngay mà không khiến Ctrl+C làm chương trình bị crash, với mức coverage phù hợp cho các trình duyệt trên terminal.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
desktop-dev
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.