def multireader(*streams):
 class reader(object, ):
  def __init__(self, stream):
   self.stream = stream
  def __call__(self):
   self.text = self.stream.readlines()
 threads = []
 readers = []
 for stream in streams:
  curReader = reader(stream)
  thread = Threading.Thread(Threading.ThreadStart(curReader))
  readers.append(curReader)
  threads.append(thread)
  thread.Start()
 for thread in threads:
  thread.Join()
 return [curReader.text for curReader in readers]

def multireader ( * streams ) : class reader ( object , ) : def __init__ ( self , stream ) : self . stream = stream def __call__ ( self ) : self . text = self . stream . readlines ( ) threads = [ ] readers = [ ] for stream in streams : curReader = reader ( stream ) thread = Threading . Thread ( Threading . ThreadStart ( curReader ) ) readers . append ( curReader ) threads . append ( thread ) thread . Start ( ) for thread in threads : thread . Join ( ) return [ curReader . text for curReader in readers ]
creates multiple threads to read std err/std out at the same time to avoid blocking .