Skip to content

Commit

Permalink
Check for non-zero length first in read loop (#2465)
Browse files Browse the repository at this point in the history
Since both the Python 2 and Python 3 cases need to handle the case of
zero and non-zero length separately, pull this check outside of the
Python 2 or 3 version checks to simplify the code a bit.
  • Loading branch information
jakirkham authored and mrocklin committed Jan 16, 2019
1 parent dfad76f commit 4fef1ad
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions distributed/comm/tcp.py
Expand Up @@ -186,16 +186,15 @@ def read(self, deserializers=None):

frames = []
for length in lengths:
if PY3 and self._iostream_has_read_into:
frame = bytearray(length)
if length:
if length:
if PY3 and self._iostream_has_read_into:
frame = bytearray(length)
n = yield stream.read_into(frame)
assert n == length, (n, length)
else:
if length:
frame = yield stream.read_bytes(length)
else:
frame = b''
frame = yield stream.read_bytes(length)
else:
frame = b''
frames.append(frame)
except StreamClosedError as e:
self.stream = None
Expand Down

0 comments on commit 4fef1ad

Please sign in to comment.