summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorAlexander Buchkovsky <olex.buchkovsky@gmail.com>2018-11-06 19:38:34 (GMT)
committerAntoine Pitrou <pitrou@free.fr>2018-11-06 19:38:34 (GMT)
commitbccacd19fa7b56dcf2fbfab15992b6b94ab6666b (patch)
tree5b74440178c378684e5e2ce579975d6dbf29c16a /Lib/multiprocessing
parent75d9d59ab3a372d3d78e6a1f5e9f256e29d0a9a6 (diff)
downloadcpython-bccacd19fa7b56dcf2fbfab15992b6b94ab6666b.zip
cpython-bccacd19fa7b56dcf2fbfab15992b6b94ab6666b.tar.gz
cpython-bccacd19fa7b56dcf2fbfab15992b6b94ab6666b.tar.bz2
bpo-17560: Too small type for struct.pack/unpack in mutliprocessing.Connection (GH-10305)
Allow sending more than 2 GB at once on a multiprocessing connection on non-Windows systems.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/connection.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
index 1f3ea50..c9f995e 100644
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -389,23 +389,33 @@ class Connection(_ConnectionBase):
def _send_bytes(self, buf):
n = len(buf)
- # For wire compatibility with 3.2 and lower
- header = struct.pack("!i", n)
- if n > 16384:
- # The payload is large so Nagle's algorithm won't be triggered
- # and we'd better avoid the cost of concatenation.
+ if n > 0x7fffffff:
+ pre_header = struct.pack("!i", -1)
+ header = struct.pack("!Q", n)
+ self._send(pre_header)
self._send(header)
self._send(buf)
else:
- # Issue #20540: concatenate before sending, to avoid delays due
- # to Nagle's algorithm on a TCP socket.
- # Also note we want to avoid sending a 0-length buffer separately,
- # to avoid "broken pipe" errors if the other end closed the pipe.
- self._send(header + buf)
+ # For wire compatibility with 3.7 and lower
+ header = struct.pack("!i", n)
+ if n > 16384:
+ # The payload is large so Nagle's algorithm won't be triggered
+ # and we'd better avoid the cost of concatenation.
+ self._send(header)
+ self._send(buf)
+ else:
+ # Issue #20540: concatenate before sending, to avoid delays due
+ # to Nagle's algorithm on a TCP socket.
+ # Also note we want to avoid sending a 0-length buffer separately,
+ # to avoid "broken pipe" errors if the other end closed the pipe.
+ self._send(header + buf)
def _recv_bytes(self, maxsize=None):
buf = self._recv(4)
size, = struct.unpack("!i", buf.getvalue())
+ if size == -1:
+ buf = self._recv(8)
+ size, = struct.unpack("!Q", buf.getvalue())
if maxsize is not None and size > maxsize:
return None
return self._recv(size)