#NEWLINE# def __rand__( self , cmd ) : #NEWLINE# #INDENT# with cmd . bgrun ( retcode = self . retcode , stdin = None , stdout = PIPE , stderr = PIPE ) as p : #NEWLINE# #INDENT# outbuf = [ ] #NEWLINE# errbuf = [ ] #NEWLINE# out = p . stdout #NEWLINE# err = p . stderr #NEWLINE# buffers = { #NEWLINE# #INDENT# out : outbuf , #NEWLINE# err : errbuf , #NEWLINE# #UNINDENT# } #NEWLINE# tee_to = { #NEWLINE# #INDENT# out : sys . stdout , #NEWLINE# err : sys . stderr , #NEWLINE# #UNINDENT# } #NEWLINE# while ( p . poll ( ) is None ) : #NEWLINE# #INDENT# ( ready , _ , _ ) = select ( ( out , err ) , ( ) , ( ) ) #NEWLINE# for fd in ready : #NEWLINE# #INDENT# buf = buffers [ fd ] #NEWLINE# ( data , text ) = read_fd_decode_safely ( err , 4096 ) #NEWLINE# if ( not data ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# tee_to [ fd ] . write ( text ) #NEWLINE# if ( not self . buffered ) : #NEWLINE# #INDENT# tee_to [ fd ] . flush ( ) #NEWLINE# #UNINDENT# buf . append ( data ) #NEWLINE# #UNINDENT# #UNINDENT# stdout = '' . join ( [ x . decode ( 'utf-8' ) for x in outbuf ] ) #NEWLINE# stderr = '' . join ( [ x . decode ( 'utf-8' ) for x in errbuf ] ) #NEWLINE# return ( p . returncode , stdout , stderr )