Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b87831

Browse files
committed
Simplify code in multiprocessing.Connection.send_bytes().
Followup to issue #20540; patch by Serhiy.
1 parent cac9e71 commit 0b87831

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

Lib/multiprocessing/connection.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,14 @@ def _send_bytes(self, buf):
400400
if n > 16384:
401401
# The payload is large so Nagle's algorithm won't be triggered
402402
# and we'd better avoid the cost of concatenation.
403-
chunks = [header, buf]
404-
elif n > 0:
403+
self._send(header)
404+
self._send(buf)
405+
else:
405406
# Issue # 20540: concatenate before sending, to avoid delays due
406407
# to Nagle's algorithm on a TCP socket.
407-
chunks = [header + buf]
408-
else:
409-
# This code path is necessary to avoid "broken pipe" errors
410-
# when sending a 0-length buffer if the other end closed the pipe.
411-
chunks = [header]
412-
for chunk in chunks:
413-
self._send(chunk)
408+
# Also note we want to avoid sending a 0-length buffer separately,
409+
# to avoid "broken pipe" errors if the other end closed the pipe.
410+
self._send(header + buf)
414411

415412
def _recv_bytes(self, maxsize=None):
416413
buf = self._recv(4)

0 commit comments

Comments
 (0)