class_docstr: Some little helper to deal with cookies
  
  Lazy loading from the shelved dictionary
  
  TODO: this is not multiprocess or multi-thread safe implementation due to shelve auto saving etc
class_docstr_tok: ["Some","little","helper","to","deal","with","cookies","Lazy","loading","from","the","shelved","dictionary","TODO",":","this","is","not","multiprocess","or","multi-thread","safe","implementation","due","to","shelve","auto","saving","etc"]
code: def close(self) -> None:
      if self._cookies_db is not None:
          try:
              # It might print out traceback right on the terminal instead of
              # just throwing an exception
              known_cookies = list(self._cookies_db)
          except Exception:
              # May be already not accessible
              known_cookies = None
          try:
              self._cookies_db.close()
          except Exception as exc:
              ce = CapturedException(exc)
              if known_cookies:
                  lgr.warning(
                      "Failed to save possibly updated %d cookies (%s): %s",
                      len(known_cookies),
                      ", ".join(known_cookies),
                      ce,
                  )
          # no cookies - no worries!
          self._cookies_db = None
  
file_path: datalad/datalad/support/cookies.py
imports: from __future__ import annotations
  import atexit
  import logging
  import os.path
  import shelve
  from pathlib import Path
  from typing import Any, Optional
  import platformdirs
  from datalad.support.exceptions import CapturedException
  from .network import get_tld
label_desc: Use image node_id 4 for calling the CookiesDB obj's underlying member method code with example usage: obj.close() without return types