code: def detach_popen(**kwargs):
      
      # This allows Popen() to be used for e.g. graceful post-fork error
      # handling, without tying the surrounding code into managing a Popen
      # object, which isn't possible for at least :mod:`mitogen.fork`. This
      # should be replaced by a swappable helper class in a future version.
      real_preexec_fn = kwargs.pop('preexec_fn', None)
      def preexec_fn():
          if _preexec_hook:
              _preexec_hook()
          if real_preexec_fn:
              real_preexec_fn()
      proc = subprocess.Popen(preexec_fn=preexec_fn, **kwargs)
      proc._child_created = False
      return proc.pid
docs: Use :class:`subprocess.Popen` to construct a child process, then hack the
      Popen so that it forgets the child it created, allowing it to survive a
      call to Popen.__del__.
  
      If the child process is not detached, there is a race between it exitting
      and __del__ being called. If it exits before __del__ runs, then __del__'s
      call to :func:`os.waitpid` will capture the one and only exit event
      delivered to this process, causing later 'legitimate' calls to fail with
      ECHILD.
  
      :param list close_on_error:
          Array of integer file descriptors to close on exception.
      :returns:
          Process ID of the new child.