open_url_in_browser: Surround subprocess creation with try-catch

Resolves #1363
This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2026-04-23 11:03:32 +02:00
1 parent d5724c4bd5
commit 885266ffb0
1 file changed
+12 -7
+12 -7
View File
@@ -800,13 +800,18 @@ def open_url_in_browser(url: str, use_subprocess: bool = False) -> None:
"""
if use_subprocess:
# Use a subprocess to avoid any output from webbrowser.open being written to stdout
subprocess.Popen(
[sys.executable, "-c", f"import webbrowser; webbrowser.open({url!r})"],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
start_new_session=False,
)
try:
subprocess.Popen(
[sys.executable, "-c", f"import webbrowser; webbrowser.open({url!r})"],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
start_new_session=False,
)
except Exception as e:
# Subprocess creation can fail in rare cases (e.g. on some Linux systems; possibly subprocess/glibc bug)
# See #1363
log.error("Failed to open URL (%s) in subprocess; %s", url, e)
else:
import webbrowser