Skip to content

Commit ede1ebb

Browse files
authored
Merge pull request matplotlib#30256 from jkseppan/timeout-get-executable-info
Time out in _get_executable_info
2 parents 73d0317 + 6a01311 commit ede1ebb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
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 {cbook._pformat_subprocess(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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import subprocess
33
import sys
4+
from unittest.mock import patch
45

56
import pytest
67

@@ -80,3 +81,16 @@ def test_importable_with__OO():
8081
[sys.executable, "-OO", "-c", program],
8182
env={**os.environ, "MPLBACKEND": ""}, check=True
8283
)
84+
85+
86+
@patch('matplotlib.subprocess.check_output')
87+
def test_get_executable_info_timeout(mock_check_output):
88+
"""
89+
Test that _get_executable_info raises ExecutableNotFoundError if the
90+
command times out.
91+
"""
92+
93+
mock_check_output.side_effect = subprocess.TimeoutExpired(cmd=['mock'], timeout=30)
94+
95+
with pytest.raises(matplotlib.ExecutableNotFoundError, match='Timed out'):
96+
matplotlib._get_executable_info.__wrapped__('inkscape')

0 commit comments

Comments
 (0)