From 4c743cf8af0443be538587c3301d6106f3456a24 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 23 May 2021 14:07:11 +0800 Subject: [PATCH] revert busy polling --- artiq/coredevice/comm_kernel.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/artiq/coredevice/comm_kernel.py b/artiq/coredevice/comm_kernel.py index 4b678f165..cdb54a118 100644 --- a/artiq/coredevice/comm_kernel.py +++ b/artiq/coredevice/comm_kernel.py @@ -217,13 +217,13 @@ class CommKernel: def _read(self, length): # cache the reads to avoid frequent call to recv while len(self.read_buffer) < length: - while True: - try: - flag = socket.MSG_DONTWAIT - new_buffer = self.socket.recv(8192, flag) - break - except BlockingIOError: - pass + # the number is just the maximum amount + # when there is not much data, it would return earlier + diff = length - len(self.read_buffer) + flag = 0 + if diff > 8192: + flag |= socket.MSG_WAITALL + new_buffer = self.socket.recv(8192, flag) if not new_buffer: raise ConnectionResetError("Core device connection closed unexpectedly") self.read_buffer += new_buffer