python / python/cpython

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

Abierto
#125,231 4 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza revisando el PR enlazado gh-149255 y, a continuación, inspecciona el punto de entrada webbrowser.open y cómo gestiona la variable de entorno BROWSER. Reproduce el script proporcionado en Linux con Firefox configurado y considera completado el issue cuando iniciar el navegador configurado devuelva el control de inmediato sin que Ctrl+C provoque un fallo, con la cobertura correspondiente para navegadores de terminal.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
desktop-dev
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.