import errno
import io
+import itertools
import os
+import stat
import sys
import socket
import struct
-import time
import tempfile
-import itertools
+import time
from . import util
f.write(ov.getbuffer())
return f
+"""
+The default size of a pipe on Linux systems is 16 times the base page size:
+https://man7.org/linux/man-pages/man7/pipe.7.html
+"""
+PAGES_PER_PIPE = 16
class Connection(_ConnectionBase):
"""
_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 * PAGES_PER_PIPE
def _send(self, buf, write=_write):
remaining = len(buf)
buf = io.BytesIO()
handle = self._handle
remaining = size
+ is_pipe = False
+ 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:
- chunk = read(handle, remaining)
+ to_read = min(limit, remaining)
+ chunk = read(handle, to_read)
n = len(chunk)
if n == 0:
if remaining == size: