def close_filenos(preserve):
 maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
 if (maxfd == resource.RLIM_INFINITY):
  maxfd = 4096
 for fileno in range(maxfd):
  if (fileno not in preserve):
   try:
    os.close(fileno)
   except OSError as err:
    if (not (err.errno == errno.EBADF)):
     raise DaemonError('Failed to close file descriptor {0}: {1}'.format(fileno, err))

def close_filenos ( preserve ) : maxfd = resource . getrlimit ( resource . RLIMIT_NOFILE ) [ 1 ] if ( maxfd == resource . RLIM_INFINITY ) : maxfd = 4096 for fileno in range ( maxfd ) : if ( fileno not in preserve ) : try : os . close ( fileno ) except OSError as err : if ( not ( err . errno == errno . EBADF ) ) : raise DaemonError ( 'Failed to close file descriptor {0}: {1}' . format ( fileno , err ) )
close unprotected file descriptors close all open file descriptors that are not in preserve .