--- a/eric6/DebugClients/Python/AsyncFile.py Sun Jan 17 13:53:08 2021 +0100 +++ b/eric6/DebugClients/Python/AsyncFile.py Mon Feb 01 10:38:16 2021 +0100 @@ -9,6 +9,7 @@ """ import socket +import threading from DebugUtilities import prepareJsonCommand @@ -58,6 +59,7 @@ self.newlines = None self.line_buffering = False + self.writeLock = threading.RLock() self.wpending = [] def __checkMode(self, mode): @@ -99,6 +101,7 @@ """ Public method to write all pending entries. """ + self.writeLock.acquire() while self.wpending: try: buf = self.wpending.pop(0) @@ -116,6 +119,7 @@ self.nWriteErrors += 1 if self.nWriteErrors > self.maxtries: self.wpending = [] # delete all output + self.writeLock.release() def isatty(self): """ @@ -191,8 +195,10 @@ length = int(length) data = b'' while len(data) < length: - newData = self.sock.recv(length - len(data)) - data += newData + newByte = self.sock.recv(1) + data += newByte + if newByte == b'\n': + break # step 2: convert the data return data.decode('utf8', 'backslashreplace') @@ -337,15 +343,18 @@ """ self.__checkMode('w') + self.writeLock.acquire() if isinstance(s, (bytes, bytearray)): # convert to string to send it s = repr(s) cmd = prepareJsonCommand("ClientOutput", { "text": s, + "debuggerId": "", }) self.wpending.append(cmd) self.flush() + self.writeLock.release() def write_p(self, s): """