[Python-checkins] cpython: Simplify code in multiprocessing.Connection.send_bytes().

antoine.pitrou python-checkins at python.org
Fri Aug 1 00:47:12 CEST 2014


http://hg.python.org/cpython/rev/20fd13242a45
changeset: 91950:20fd13242a45
user: Antoine Pitrou <solipsis at pitrou.net>
date: Thu Jul 31 18:41:57 2014 -0400
summary:
 Simplify code in multiprocessing.Connection.send_bytes().
Followup to issue #20540; patch by Serhiy.
files:
 Lib/multiprocessing/connection.py | 15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py
--- a/Lib/multiprocessing/connection.py
+++ b/Lib/multiprocessing/connection.py
@@ -400,17 +400,14 @@
 if n > 16384:
 # The payload is large so Nagle's algorithm won't be triggered
 # and we'd better avoid the cost of concatenation.
- chunks = [header, buf]
- elif n > 0:
+ self._send(header)
+ self._send(buf)
+ else:
 # Issue # 20540: concatenate before sending, to avoid delays due
 # to Nagle's algorithm on a TCP socket.
- chunks = [header + buf]
- else:
- # This code path is necessary to avoid "broken pipe" errors
- # when sending a 0-length buffer if the other end closed the pipe.
- chunks = [header]
- for chunk in chunks:
- self._send(chunk)
+ # 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)
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /