我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用gevent.reinit()。
def daemon(user, group, path='/', pidfile='/tmp/%s.pid' % __default_servicename__, other_groups=()): ''' Daemonizes current application. ''' # Get uid and gid from user and group names uid = int(pwd.getpwnam(user)[2]) gid = int(grp.getgrnam(group)[2]) # Get ID of other groups other_groups_id = [] for name in other_groups: try: other_groups_id.append(int(grp.getgrnam(name)[2]) ) except: pass # First fork pid = gevent.fork() if not pid == 0: os._exit(0) # Creates a session and sets the process group ID os.setsid() # Second fork pid = gevent.fork() if not pid == 0: os._exit(0) # Change directoty os.chdir(path) # Set umask os.umask(0) # Write pidfile open(pidfile, 'w').write(str(os.getpid())) # Set group and groups os.setgid(gid) if other_groups_id: os.setgroups(other_groups_id) # Set user os.setuid(uid) # Redirect stdout/stderr to /dev/null sys.stdout = sys.stderr = open(os.devnull, 'a+') gevent.reinit()