From 1b974d0d048202da1f978849ba268d05ef9653b2 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Wed, 28 Jul 2021 15:49:28 -0700 Subject: [PATCH] Always cast frames to `memoryview`s --- distributed/comm/tcp.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/distributed/comm/tcp.py b/distributed/comm/tcp.py index 7dfe78f5eb..e984b00dfc 100644 --- a/distributed/comm/tcp.py +++ b/distributed/comm/tcp.py @@ -271,10 +271,11 @@ async def write(self, msg, serializers=None, on_error="message"): if stream._write_buffer is None: raise StreamClosedError() - if isinstance(each_frame, memoryview): - # Make sure that `len(data) == data.nbytes` - # See - each_frame = each_frame.cast("B") + each_frame = memoryview(each_frame) + + # Make sure that `len(data) == data.nbytes` + # See + each_frame = each_frame.cast("B") stream._write_buffer.append(each_frame) stream._total_write_index += each_frame_nbytes