- class ReadThread (threading.Thread):
- """Thread which reads from sub-process output"""
-
- def __init__( self, stream, callback, sleep=0.1):
- self.stream = stream
- self.fin = False
- self.callback = callback
- self.sleep = sleep
- self.eventFin = threading.Event()
- threading.Thread.__init__(self)
-
- def run(self):
-
- try:
- while True:
- #Wait until data is available
- rlist, wlist, xlist = select.select([self.stream], [], [], self.sleep)
-
- #If we should finish, finish
- if self.fin:
- break
-
- #Got new data
- if len(rlist) > 0:
- fd = rlist[0]
- str = fd.read(1)
- #Call callbacks
- self.callback(str)
- except:
- pass
-
- #Set the finished event
- self.eventFin.set()
-
-
-