`webbrowser.open` hangs indefinitely when exiting browser defined in `BROWSER` environment variable
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando la PR collegata gh-149255, quindi analizza l’entry point webbrowser.open e la gestione della variabile d’ambiente BROWSER. Riproduci lo script fornito su Linux con Firefox configurato e considera completata la issue quando l’avvio del browser configurato restituisce prontamente il controllo senza che Ctrl+C provochi un crash, con una copertura adeguata per i browser da terminale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- desktop-dev
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100