8000 gh-121313: Limit the reading size from pipes to their default buffer size on Unix systems by aplaikner · Pull Request #121315 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-121313: Limit the reading size from pipes to their default buffer size on Unix systems #121315

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
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Shift calculation for pipe size to existing if _winapi check
  • Loading branch information
aplaikner committed Jul 7, 2024
commit e726f5142f769a61989220f09b9548626ebfa819
14 changes: 7 additions & 7 deletions Lib/multiprocessing/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,14 @@ def _close(self, _close=_multiprocessing.closesocket):
_close(self._handle)
_write = _multiprocessing.send
_read = _multiprocessing.recv
_default_pipe_size = 0
else:
def _close(self, _close=os.close):
_close(self._handle)
_write = os.write
_read = os.read
_base_page_size = os.sysconf(os.sysconf_names['SC_PAGESIZE'])
_default_pipe_size = _base_page_size * 16

def _send(self, buf, write=_write):
remaining = len(buf)
Expand All @@ -393,13 +396,10 @@ def _recv(self, size, read=_read):
handle = self._handle
remaining = size
is_pipe = False
page_size = 0
if not _winapi:
page_size = os.sysconf(os.sysconf_names['SC_PAGESIZE'])
if size > 16 * page_size:
mode = os.fstat(handle).st_mode
is_pipe = stat.S_ISFIFO(mode)
limit = 16 * page_size if is_pipe else remaining
if size > self._default_pipe_size > 0:
mode = os.fstat(handle).st_mode
is_pipe = stat.S_ISFIFO(mode)
limit = self._default_pipe_size if is_pipe else remaining
while remaining > 0:
to_read = min(limit, remaining)
chunk = read(handle, to_read)
Expand Down
Loading
0