class_docstr: A class to organize all history-related functionality in one place.
      
class_docstr_tok: ["A","class","to","organize","all","history-related","functionality","in","one","place","."]
docstr: Write any entries in the cache to the database.
docstr_tok: ["Write","any","entries","in","the","cache","to","the","database","."]
code: def writeout_cache(self, conn=None):
      """Write any entries in the cache to the database."""
      if conn is None:
          conn = self.db
  
      with self.db_input_cache_lock:
          try:
              self._writeout_input_cache(conn)
          except sqlite3.IntegrityError:
              self.new_session(conn)
              print(
                  "ERROR! Session/line number was not unique in",
                  "database. History logging moved to new session",
                  self.session_number,
              )
              try:
                  # Try writing to the new session. If this fails, don't
                  # recurse
                  self._writeout_input_cache(conn)
              except sqlite3.IntegrityError:
                  pass
          finally:
              self.db_input_cache = []
  
      with self.db_output_cache_lock:
          try:
              self._writeout_output_cache(conn)
          except sqlite3.IntegrityError:
              print(
                  "!! Session/line number for output was not unique",
                  "in database. Output will not be stored.",
              )
          finally:
              self.db_output_cache = []
  
imports: import atexit
  import datetime
  from pathlib import Path
  import re
  import sqlite3
  import threading
  from traitlets.config.configurable import LoggingConfigurable
  from decorator import decorator
  from IPython.utils.decorators import undoc
  from IPython.paths import locate_profile
  from traitlets import Any, Bool, Dict, Instance, Integer, List, Unicode, Union, TraitError, default, observe
label_desc: Use image node_id 16 for calling the HistoryManager obj's underlying member method code with example usage: obj.writeout_cache(conn) without return types