

def daemonize(self):
    'Daemonize process by doing Stevens double fork.'
    if (self.stdout is not DEVNULL):
        self.stdout.flush()
    if (self.stderr is not DEVNULL):
        self.stderr.flush()
    for f in (sys.stdout, sys.stderr):
        f.flush()
    self._fork()
    os.chdir('/')
    os.setsid()
    os.umask(0)
    self._fork()
    with open(os.devnull, 'w+') as devnull:
        stdin = (devnull if (self.stdin is DEVNULL) else self.stdin)
        stdout = (devnull if (self.stdout is DEVNULL) else self.stdout)
        stderr = (devnull if (self.stderr is DEVNULL) else self.stderr)
        os.dup2(stdin.fileno(), STDIN_FILENO)
        os.dup2(stdout.fileno(), STDOUT_FILENO)
        os.dup2(stderr.fileno(), STDERR_FILENO)
    if (self.pidfile is not None):
        atexit.register(self.delete_pid)
        signal.signal(signal.SIGTERM, self.handle_sigterm)
        self.pidfile.write(os.getpid())

dataset/ETHPy150Open openstack/neutron/neutron/agent/linux/daemon.py Daemon.daemonize/original