Skip to content

Commit

Permalink
Type and mute _find_system_pipe_max
Browse files Browse the repository at this point in the history
This hack leaves unclosed resources and emits a warning. Lets mute it, and type
the function properly.
  • Loading branch information
berland committed Aug 26, 2024
1 parent 4bca2ba commit 641aa0d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/unit_tests/shared/share/test_subprocess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings
from subprocess import PIPE, Popen, TimeoutExpired

import pytest
Expand Down Expand Up @@ -26,20 +27,23 @@
)


def _find_system_pipe_max_size():
def _find_system_pipe_max_size() -> int:
"""This method finds the limit of the system pipe-buffer which
might be taken into account when using subprocesses with pipes."""
p = Popen(["dd", "if=/dev/zero", "bs=1"], stdin=PIPE, stdout=PIPE)
try:
p.wait(timeout=1)
except TimeoutExpired:
p.kill()
assert p.stdout is not None
return len(p.stdout.read())

return None
return 2**16


warnings.simplefilter("ignore", ResourceWarning)
_maxBytes = _find_system_pipe_max_size() - 1
warnings.resetwarnings()


@pytest.mark.usefixtures("use_tmpdir")
Expand Down

0 comments on commit 641aa0d

Please sign in to comment.