56 self.encoding = "utf-8" |
57 self.encoding = "utf-8" |
57 self.errors = None |
58 self.errors = None |
58 self.newlines = None |
59 self.newlines = None |
59 self.line_buffering = False |
60 self.line_buffering = False |
60 |
61 |
|
62 self.writeLock = threading.RLock() |
61 self.wpending = [] |
63 self.wpending = [] |
62 |
64 |
63 def __checkMode(self, mode): |
65 def __checkMode(self, mode): |
64 """ |
66 """ |
65 Private method to check the mode. |
67 Private method to check the mode. |
114 self.nWriteErrors = 0 |
117 self.nWriteErrors = 0 |
115 except OSError: |
118 except OSError: |
116 self.nWriteErrors += 1 |
119 self.nWriteErrors += 1 |
117 if self.nWriteErrors > self.maxtries: |
120 if self.nWriteErrors > self.maxtries: |
118 self.wpending = [] # delete all output |
121 self.wpending = [] # delete all output |
|
122 self.writeLock.release() |
119 |
123 |
120 def isatty(self): |
124 def isatty(self): |
121 """ |
125 """ |
122 Public method to indicate whether a tty interface is supported. |
126 Public method to indicate whether a tty interface is supported. |
123 |
127 |
337 @param s text to be written |
341 @param s text to be written |
338 @type str, bytes or bytearray |
342 @type str, bytes or bytearray |
339 """ |
343 """ |
340 self.__checkMode('w') |
344 self.__checkMode('w') |
341 |
345 |
|
346 self.writeLock.acquire() |
342 if isinstance(s, (bytes, bytearray)): |
347 if isinstance(s, (bytes, bytearray)): |
343 # convert to string to send it |
348 # convert to string to send it |
344 s = repr(s) |
349 s = repr(s) |
345 |
350 |
346 cmd = prepareJsonCommand("ClientOutput", { |
351 cmd = prepareJsonCommand("ClientOutput", { |
347 "text": s, |
352 "text": s, |
348 "debuggerId": "", |
353 "debuggerId": "", |
349 }) |
354 }) |
350 self.wpending.append(cmd) |
355 self.wpending.append(cmd) |
351 self.flush() |
356 self.flush() |
|
357 self.writeLock.release() |
352 |
358 |
353 def write_p(self, s): |
359 def write_p(self, s): |
354 """ |
360 """ |
355 Public method to write a json-rpc 2.0 coded string to the file. |
361 Public method to write a json-rpc 2.0 coded string to the file. |
356 |
362 |