8000 Time out in _get_executable_info · matplotlib/matplotlib@38a4c3b · GitHub
[go: up one dir, main page]

Skip to content

Commit 38a4c3b

Browse files
committed
Time out in _get_executable_info
Time out after 30 seconds. This is used for version queries which should be very fast, so a 30-second delay would be unusual. GitHub Actions test runs have been hanging trying to get the inkscape version when using Python 3.14: https://github.com/matplotlib/matplotlib/actions/runs/16043158943/job/45268507848#step:13:836
1 parent 70d5ad4 commit 38a4c3b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/matplotlib/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,15 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
400400
try:
401401
output = subprocess.check_output(
402402
args, stderr=subprocess.STDOUT,
403-
text=True, errors="replace")
403+
text=True, errors="replace", timeout=30)
404404
except subprocess.CalledProcessError as _cpe:
405405
if ignore_exit_code:
406406
output = _cpe.output
407407
else:
408408
raise ExecutableNotFoundError(str(_cpe)) from _cpe
409+
except subprocess.TimeoutExpired as _te:
410+
msg = f"Timed out running {' '.join(args)}"
411+
raise ExecutableNotFoundError(msg) from _te
409412
except OSError as _ose:
410413
raise ExecutableNotFoundError(str(_ose)) from _ose
411414
match = re.search(regex, output)

lib/matplotlib/tests/test_matplotlib.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import subprocess
33
import sys
4-
4+
from unittest.mock import patch
55
import pytest
66

77
import matplotlib
@@ -80,3 +80,18 @@ def test_importable_with__OO():
8080
[sys.executable, "-OO", "-c", program],
8181
env={**os.environ, "MPLBACKEND": ""}, check=True
8282
)
83+
84+
85+
@patch('matplotlib.subprocess.check_output')
86+
def test_get_executable_info_timeout(mock_check_output):
87+
"""
88+
Test that _get_executable_info raises ExecutableNotFoundError if the
89+
command times out.
90+
"""
91+
92+
mock_check_output.side_effect = subprocess.TimeoutExpired(cmd=['mock'], timeout=30)
93+
94+
with pytest.raises(matplotlib.ExecutableNotFoundError) as exc_info:
95+
print(matplotlib._get_executable_info.__wrapped__('inkscape'))
96+
97+
assert "Timed out" in str(exc_info.value)

0 commit comments

Comments
 (0)
0