Browse Source

Lock output so that terminal escape sequences don't mix

master
Jim Paris 2 years ago
parent
commit
7c536a2d6b
1 changed files with 6 additions and 0 deletions
  1. +6
    -0
      terminal.py

+ 6
- 0
terminal.py View File

@@ -150,6 +150,7 @@ class Jimterm:
self.raw = raw
self.bufsize = bufsize
self.quote_re = None
self.output_lock = threading.Lock()

def print_header(self, nodes, bauds, output = sys.stdout):
for (n, (node, baud)) in enumerate(zip(nodes, bauds)):
@@ -225,6 +226,8 @@ class Jimterm:
data = data[1:]
first = False

self.output_lock.acquire()

if color != self.last_color:
self.last_color = color
os.write(sys.stdout.fileno(), color)
@@ -239,6 +242,9 @@ class Jimterm:
data = self.quote_raw(data)

os.write(sys.stdout.fileno(), data)

self.output_lock.release()

except Exception as e:
self.console.cleanup()
sys.stdout.write(color)


Loading…
Cancel
Save