title: Launch a completely independent process
body: <p>I want to initiate a process from my python script <code>main.py</code>. Specifically, I want to run the below command:</p>
  
  <pre><code>`nohup python ./myfile.py &amp;`
  </code></pre>
  
  <p>and the file <code>myfile.py</code> should continue running, even after the <code>main.py</code> script exits.</p>
  
  <p>I also wish to get the <code>pid</code> of the new process.</p>
  
  <p>I tried:</p>
  
  <ul>
  <li><code>os.spawnl*</code></li>
  <li><code>os.exec*</code></li>
  <li><code>subprocess.Popen</code></li>
  </ul>
  
  <p>and all are terminating the <code>myfile.py</code> when the <code>main.py</code> script exits.</p>
  
  <hr>
  
  <p><strong>Update:</strong> Can I use <code>os.startfile</code> with <code>xdg-open</code>? Is it the right approach?</p>
  
  <hr>
  
  <p><strong>Example</strong></p>
  
  <pre><code>a = subprocess.Popen([sys.executable, "nohup /usr/bin/python25 /long_process.py &amp;"],\
       stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  print a.pid
  </code></pre>
  
  <p>If I check <code>ps aux | grep long_process</code>, there is no process running.</p>
  
  <p><strong>long_process.py</strong> which keeps on printing some text: no exit.</p>
  
  <p>Am I doing anything wrong here?</p>