title: Difference between subprocess.Popen preexec_fn and start_new_session in python
body: <p>What is the difference between these two options to start a new process with <code>subprocess.Popen</code> for <code>python3.2+</code> under <code>Linux</code>:</p>
  
  <pre><code>proc = subprocess.Popen(args, ..., preexec_fn=os.setsid)   # 1
  proc = subprocess.Popen(args, ..., start_new_session=True) # 2
  </code></pre>
  
  <p>I need this as I need to set process group ID to have a possibility to kill at once this process and all of its children. This is then used in the case if the process run time exceeds certain threshold:</p>
  
  <pre><code>try:
      out, err = proc.communicate(timeout=time_max)
  except subprocess.TimeoutExpired:
      os.killpg(os.getpgid(proc.pid), signal.SIGTERM) 
  </code></pre>
  
  <p>I tested my code with the both options (<code>#1</code> &amp; <code>#2</code>) and they both seem to work ok for me. </p>
  
  <p>But I wonder what is the best option here - the one with <code>preexec_fn</code> or the one with <code>start_new_session</code>?</p>