Subthread reads also need to be serialized
authorJack Miller <jack@codezen.org>
Tue, 28 Oct 2014 19:06:15 +0000 (14:06 -0500)
committerJack Miller <jack@codezen.org>
Tue, 28 Oct 2014 19:06:15 +0000 (14:06 -0500)
canto_curses/subthread.py

index fc0bebe..bd4de87 100644 (file)
@@ -20,6 +20,7 @@ class SubThread(object):
         self.backend = backend
 
         self.wlock = Lock()
+        self.rlock = Lock()
 
         # Start up our own connection
         self.conn = backend.connect()
@@ -43,7 +44,10 @@ class SubThread(object):
         self.wlock.release()
 
     def read(self):
-        return self.backend.do_read(self.conn)
+        self.rlock.acquire()
+        r = self.backend.do_read(self.conn)
+        self.rlock.release()
+        return r
 
     def pthread(self):
         self.alive = True