def run_background_process(cmd, out_log=None, err_log=None, cwd=None):
 kwargs = {'shell': True, 'cwd': cwd}
 if out_log:
  out_log_file = open(out_log, 'w')
  kwargs['stdout'] = out_log_file
 if err_log:
  err_log_file = open(err_log, 'w')
  kwargs['stderr'] = err_log_file
 proc = subprocess.Popen(cmd, **kwargs)
 def exit_handler():
  "\n        Send SIGINT to the process's children. This is important\n        for running commands under coverage, as coverage will not\n        produce the correct artifacts if the child process isn't\n        killed properly.\n        "
  p1_group = psutil.Process(proc.pid)
  child_pids = p1_group.get_children(recursive=True)
  for child_pid in child_pids:
   os.kill(child_pid.pid, signal.SIGINT)
  proc.wait()
 atexit.register(exit_handler)

def run_background_process ( cmd , out_log = None , err_log = None , cwd = None ) : kwargs = { 'shell' : True , 'cwd' : cwd } if out_log : out_log_file = open ( out_log , 'w' ) kwargs [ 'stdout' ] = out_log_file if err_log : err_log_file = open ( err_log , 'w' ) kwargs [ 'stderr' ] = err_log_file proc = subprocess . Popen ( cmd , ** kwargs ) def exit_handler ( ) : p1_group = psutil . Process ( proc . pid ) child_pids = p1_group . get_children ( recursive = True ) for child_pid in child_pids : os . kill ( child_pid . pid , signal . SIGINT ) proc . wait ( ) atexit . register ( exit_handler )
runs a command as a background process .