#NEWLINE# def __init__( self , cmd , inputstream = None , buffer_size = 65536 , chunk_size = 4096 , starting_values = [ ] , **kwargs ) : #NEWLINE# #INDENT# '\n        Initializes SubprocessIOChunker\n\n        :param cmd: A Subprocess.Popen style "cmd". Can be string or array of strings\n        :param inputstream: (Default: None) A file-like, string, or file pointer.\n        :param buffer_size: (Default: 65536) A size of total buffer per stream in bytes.\n        :param chunk_size: (Default: 4096) A max size of a chunk. Actual chunk may be smaller.\n        :param starting_values: (Default: []) An array of strings to put in front of output que.\n        ' #NEWLINE# if inputstream : #NEWLINE# #INDENT# input_streamer = StreamFeeder ( inputstream ) #NEWLINE# input_streamer . start ( ) #NEWLINE# inputstream = input_streamer . output #NEWLINE# #UNINDENT# if isinstance ( cmd , ( list , tuple ) ) : #NEWLINE# #INDENT# cmd = ' ' . join ( cmd ) #NEWLINE# #UNINDENT# _shell = ( kwargs . get ( 'shell' ) or True ) #NEWLINE# kwargs [ 'shell' ] = _shell #NEWLINE# _p = subprocess . Popen ( cmd , bufsize = ( - 1 ) , stdin = inputstream , stdout = subprocess . PIPE , stderr = subprocess . PIPE , ** kwargs ) #NEWLINE# bg_out = BufferedGenerator ( _p . stdout , buffer_size , chunk_size , starting_values ) #NEWLINE# bg_err = BufferedGenerator ( _p . stderr , 16000 , 1 , bottomless = True ) #NEWLINE# while ( ( not bg_out . done_reading ) and ( not bg_out . reading_paused ) and ( not bg_err . length ) ) : #NEWLINE# #INDENT# bg_out . data_added_event . wait ( 1 ) #NEWLINE# bg_out . data_added_event . clear ( ) #NEWLINE# #UNINDENT# _returncode = _p . poll ( ) #NEWLINE# if ( _returncode or ( ( _returncode == None ) and bg_err . length ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# _p . terminate ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# bg_out . stop ( ) #NEWLINE# bg_err . stop ( ) #NEWLINE# err = ( '%s' % '' . join ( bg_err ) ) #NEWLINE# if err : #NEWLINE# #INDENT# raise EnvironmentError ( ( 'Subprocess exited due to an error:\n' + err ) ) #NEWLINE# #UNINDENT# raise EnvironmentError ( ( 'Subprocess exited with non 0 ret code:%s' % _returncode ) ) #NEWLINE# #UNINDENT# self . process = _p #NEWLINE# self . output = bg_out #NEWLINE# self . error = bg_err