def close_file_descriptor_if_open(fd):
 try:
  os.close(fd)
 except OSError as exc:
  if (exc.errno == errno.EBADF):
   pass
  else:
   error = DaemonOSEnvironmentError(('Failed to close file descriptor %(fd)d (%(exc)s)' % vars()))
   raise error

def close_file_descriptor_if_open ( fd ) : try : os . close ( fd ) except OSError as exc : if ( exc . errno == errno . EBADF ) : pass else : error = DaemonOSEnvironmentError ( ( 'Failed to close file descriptor %(fd)d (%(exc)s)' % vars ( ) ) ) raise error
close a file descriptor if already open .