#NEWLINE# def run( self , timeout = None , **kwargs ) : #NEWLINE# #INDENT# ' Run a command then return: (status, output, error). ' #NEWLINE# def target( **kwargs ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . process = subprocess . Popen ( self . command , ** kwargs ) #NEWLINE# ( self . output , self . error ) = self . process . communicate ( ) #NEWLINE# self . status = self . process . returncode #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# self . error = traceback . format_exc ( ) #NEWLINE# self . status = ( - 1 ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'stdout' not in kwargs ) : #NEWLINE# #INDENT# kwargs [ 'stdout' ] = subprocess . PIPE #NEWLINE# #UNINDENT# if ( 'stderr' not in kwargs ) : #NEWLINE# #INDENT# kwargs [ 'stderr' ] = subprocess . PIPE #NEWLINE# #UNINDENT# thread = threading . Thread ( target = target , kwargs = kwargs ) #NEWLINE# thread . start ( ) #NEWLINE# thread . join ( timeout ) #NEWLINE# if thread . is_alive ( ) : #NEWLINE# #INDENT# self . process . terminate ( ) #NEWLINE# thread . join ( ) #NEWLINE# #UNINDENT# return ( self . status , self . output , self . error )