super_utils/run_server/daemon.py
def daemonize(self):
        """Deamonize class. UNIX double fork mechanism."""
        try:
            pid = os.fork()
            if pid > 0:
                # exit first parent
                sys.exit(0)
        except OSError as err:
            sys.stderr.write('fork #1 failed: {0}\n'.format(err))
            sys.exit(1)

        # decouple from parent environment
        os.chdir('/')
        os.setsid()
        os.umask(0)

        # do second fork
        try:
            pid = os.fork()
            if pid > 0:
                # exit from second parent
                sys.exit(0)
        except OSError as err:
            sys.stderr.write('fork #2 failed: {0}\n'.format(err))
            sys.exit(1)

        # redirect standard file descriptors
        sys.stdout.flush()
        sys.stderr.flush()
        si = open(os.devnull, 'r')
        so = open(os.devnull, 'a+')
        se = open(os.devnull, 'a+')

        os.dup2(si.fileno(), sys.stdin.fileno())
        os.dup2(so.fileno(), sys.stdout.fileno())
        os.dup2(se.fileno(), sys.stderr.fileno())

        # write pid_file
        atexit.register(self.delpid)

        pid = str(os.getpid())
        with open(self.pid_file, 'w+') as f:
            f.write(pid + '\n')
Deamonize class. UNIX double fork mechanism.
Deamonize class. UNIX double fork mechanism.
Deamonize class . UNIX double fork mechanism .
def daemonize(self):
        try:
            pid = os.fork()
            if pid > 0:
                sys.exit(0)
        except OSError as err:
            sys.stderr.write('fork #1 failed: {0}\n'.format(err))
            sys.exit(1)
        os.chdir('/')
        os.setsid()
        os.umask(0)
        try:
            pid = os.fork()
            if pid > 0:
                sys.exit(0)
        except OSError as err:
            sys.stderr.write('fork #2 failed: {0}\n'.format(err))
            sys.exit(1)
        sys.stdout.flush()
        sys.stderr.flush()
        si = open(os.devnull, 'r')
        so = open(os.devnull, 'a+')
        se = open(os.devnull, 'a+')
        os.dup2(si.fileno(), sys.stdin.fileno())
        os.dup2(so.fileno(), sys.stdout.fileno())
        os.dup2(se.fileno(), sys.stderr.fileno())
        atexit.register(self.delpid)
        pid = str(os.getpid())
        with open(self.pid_file, 'w+') as f:
            f.write(pid + '\n')
def daemonize ( self ) : try : pid = os . fork ( ) if pid > 0 : sys . exit ( 0 ) except OSError as err : sys . stderr . write ( 'fork #1 failed: {0}\n' . format ( err ) ) sys . exit ( 1 ) os . chdir ( '/' ) os . setsid ( ) os . umask ( 0 ) try : pid = os . fork ( ) if pid > 0 : sys . exit ( 0 ) except OSError as err : sys . stderr . write ( 'fork #2 failed: {0}\n' . format ( err ) ) sys . exit ( 1 ) sys . stdout . flush ( ) sys . stderr . flush ( ) si = open ( os . devnull , 'r' ) so = open ( os . devnull , 'a+' ) se = open ( os . devnull , 'a+' ) os . dup2 ( si . fileno ( ) , sys . stdin . fileno ( ) ) os . dup2 ( so . fileno ( ) , sys . stdout . fileno ( ) ) os . dup2 ( se . fileno ( ) , sys . stderr . fileno ( ) ) atexit . register ( self . delpid ) pid = str ( os . getpid ( ) ) with open ( self . pid_file , 'w+' ) as f : f . write ( pid + '\n' )
Deamonize class.
Deamonize class .
"""Deamonize class. UNIX double fork mechanism.""" # exit first parent # decouple from parent environment # do second fork # exit from second parent # redirect standard file descriptors # write pid_file
self