eric6/DebugClients/Python/AsyncFile.py

changeset 8014
efa0c52fee56
parent 7926
5357e5ffebf1
child 8043
0acf98cd089a
child 8207
d359172d11be
diff -r ae9ab1e150dc -r efa0c52fee56 eric6/DebugClients/Python/AsyncFile.py
--- a/eric6/DebugClients/Python/AsyncFile.py	Wed Jan 27 10:06:09 2021 +0100
+++ b/eric6/DebugClients/Python/AsyncFile.py	Wed Jan 27 19:50:23 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):
         """
@@ -339,6 +343,7 @@
         """
         self.__checkMode('w')
         
+        self.writeLock.acquire()
         if isinstance(s, (bytes, bytearray)):
             # convert to string to send it
             s = repr(s)
@@ -349,6 +354,7 @@
         })
         self.wpending.append(cmd)
         self.flush()
+        self.writeLock.release()
     
     def write_p(self, s):
         """

eric ide

mercurial