def detach_process_context():
 def fork_then_exit_parent(error_message):
  ' Fork a child process, then exit the parent process.\n\n            If the fork fails, raise a ``DaemonProcessDetachError``\n            with ``error_message``.\n\n            '
  try:
   pid = os.fork()
   if (pid > 0):
    os._exit(0)
  except OSError as exc:
   exc_errno = exc.errno
   exc_strerror = exc.strerror
   error = DaemonProcessDetachError(('%(error_message)s: [%(exc_errno)d] %(exc_strerror)s' % vars()))
   raise error
 fork_then_exit_parent(error_message='Failed first fork')
 os.setsid()
 fork_then_exit_parent(error_message='Failed second fork')

def detach_process_context ( ) : def fork_then_exit_parent ( error_message ) : try : pid = os . fork ( ) if ( pid > 0 ) : os . _exit ( 0 ) except OSError as exc : exc_errno = exc . errno exc_strerror = exc . strerror error = DaemonProcessDetachError ( ( '%(error_message)s: [%(exc_errno)d] %(exc_strerror)s' % vars ( ) ) ) raise error fork_then_exit_parent ( error_message = 'Failed first fork' ) os . setsid ( ) fork_then_exit_parent ( error_message = 'Failed second fork' )
detach the process context from parent and session .