title: Deliberately make an orphan process in python
body: <p>I have a python script (unix-like, based on RHEL), called MyScript, that has two functions, called A and B. I'd like them to run in different, independent processes (detach B and A):</p>
  
  <ul>
  <li>Start script MyScript</li>
  <li>Execute function A </li>
  <li>Spawn a new process, passing data from function A to B</li>
  <li>While function B runs, continue with function A</li>
  <li>When function A completes, exit MyScript even if B is still running</li>
  </ul>
  
  <p>I thought I should use multiprocessing to create a daemon process, but the <a href="http://docs.python.org/library/multiprocessing.html#multiprocessing.Process" rel="nofollow">documentation</a> suggests that's not the right usecase. So, I decided to spawn a child process and child^2 process (the child's child), and then force the child to terminate. While this workaround appears to work, it seems really ugly. </p>
  
  <p>Can you help me make it more pythonic? Does the subprocess module have a method that will operate on a function? Sample code below.</p>
  
  <pre><code>import multiprocessing
  import time
  import sys
  import os
  
  def parent_child():
      p = multiprocessing.current_process()
      print 'Starting parent child:', p.name, p.pid
      sys.stdout.flush()
      cc = multiprocessing.Process(name='childchild', target=child_child)
      cc.daemon = False
      cc.start()
      print 'Exiting parent child:', p.name, p.pid
      sys.stdout.flush()
  
  def child_child():
      p = multiprocessing.current_process()
      print 'Starting child child:', p.name, p.pid
      sys.stdout.flush()
      time.sleep(30)
      print 'Exiting child child:', p.name, p.pid
      sys.stdout.flush()
  
  def main():
      print 'starting main', os.getpid()
      d = multiprocessing.Process(name='parentchild', target=parent_child)
      d.daemon = False
      d.start()
      time.sleep(5)
      d.terminate()
      print 'exiting main', os.getpid()
  
  main()
  </code></pre>