8000 Backport PR #30256 on branch v3.10.x (Time out in _get_executable_info) by meeseeksmachine · Pull Request #30259 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #30256 on branch v3.10.x (Time out in _get_executable_info) #30259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,15 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
try:
output = subprocess.check_output(
args, stderr=subprocess.STDOUT,
text=True, errors="replace")
text=True, errors="replace", timeout=30)
except subprocess.CalledProcessError as _cpe:
if ignore_exit_code:
output = _cpe.output
else:
raise ExecutableNotFoundError(str(_cpe)) from _cpe
except subprocess.TimeoutExpired as _te:
msg = f"Timed out running {cbook._pformat_subprocess(args)}"
raise ExecutableNotFoundError(msg) from _te
except OSError as _ose:
raise ExecutableNotFoundError(str(_ose)) from _ose
match = re.search(regex, output)
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_matplotlib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import sys
from unittest.mock import patch

import pytest

Expand Down Expand Up @@ -80,3 +81,16 @@ def test_importable_with__OO():
[sys.executable, "-OO", "-c", program],
env={**os.environ, "MPLBACKEND": ""}, check=True
)


@patch('matplotlib.subprocess.check_output')
def test_get_executable_info_timeout(mock_check_output):
"""
Test that _get_executable_info raises ExecutableNotFoundError if the
command times out.
"""

mock_check_output.side_effect = subprocess.TimeoutExpired(cmd=['mock'], timeout=30)

with pytest.raises(matplotlib.ExecutableNotFoundError, match='Timed out'):
matplotlib._get_executable_info.__wrapped__('inkscape')
Loading
0