code: def close_fds(keep_fds):  # pragma: no cover
      """Close all the file descriptors except those in keep_fds."""
  
      # Make sure to keep stdout and stderr open for logging purpose
      keep_fds = {*keep_fds, 1, 2}
  
      # We try to retrieve all the open fds
      try:
          open_fds = {int(fd) for fd in os.listdir("/proc/self/fd")}
      except FileNotFoundError:
          import resource
  
          max_nfds = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
          open_fds = {*range(max_nfds)}
  
      for i in open_fds - keep_fds:
          try:
              os.close(i)
          except OSError:
              pass
  
imports: import os
  import sys
label_desc: Use image node_id 1 for calling a global function with example usage: close_fds(keep_fds) without return types