8000 Merge pull request #30259 from meeseeksmachine/auto-backport-of-pr-30… · matplotlib/matplotlib@e0739f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0739f3

Browse files
authored
Merge pull request #30259 from meeseeksmachine/auto-backport-of-pr-30256-on-v3.10.x
Backport PR #30256 on branch v3.10.x (Time out in _get_executable_info)
2 parents 1790c88 + 3119910 commit e0739f3

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
@@ -399,12 +399,15 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
399399
try:
400400
output = subprocess.check_output(
401401
args, stderr=subprocess.STDOUT,
402-
text=True, errors="replace")
402+
text=True, errors="replace", timeout=30)
403403
except subprocess.CalledProcessError as _cpe:
404404
if ignore_exit_code:
405405
output = _cpe.output
406406
else:
407407
raise ExecutableNotFoundError(str(_cpe)) from _cpe
408+
except subprocess.TimeoutExpired as _te:
409+
msg = f"Timed out running {cbook._pformat_subprocess(args)}"
410+
raise ExecutableNotFoundError(msg) from _te
408411
except OSError as _ose:
409412
raise ExecutableNotFoundError(str(_ose)) from _ose
410413
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)
0