def timeout_command(command, timeout):
 cmd = command.split(' ')
 start = datetime.datetime.now()
 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 while (process.poll() is None):
  time.sleep(0.2)
  now = datetime.datetime.now()
  if ((now - start).seconds > timeout):
   os.system(('sudo kill %s' % process.pid))
   os.waitpid((-1), os.WNOHANG)
   return []
 return process.stdout.readlines()

def timeout_command ( command , timeout ) : cmd = command . split ( ' ' ) start = datetime . datetime . now ( ) process = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) while ( process . poll ( ) is None ) : time . sleep ( 0.2 ) now = datetime . datetime . now ( ) if ( ( now - start ) . seconds > timeout ) : os . system ( ( 'sudo kill %s' % process . pid ) ) os . waitpid ( ( - 1 ) , os . WNOHANG ) return [ ] return process . stdout . readlines ( )
call shell-command and either return its output or kill it if it doesnt normally exit within timeout seconds and return none .