class_docstr: This thread takes care of writing history to the database, so that
  the UI isn't held up while that happens.
  
  It waits for the HistoryManager's save_flag to be set, then writes out
  the history cache. The main thread is responsible for setting the flag when
  the cache size reaches a defined threshold.
class_docstr_tok: ["This","thread","takes","care","of","writing","history","to","the","database",",","so","that","the","UI","is","n't","held","up","while","that","happens",".","It","waits","for","the","HistoryManager","'s","save_flag","to","be","set",",","then","writes","out","the","history","cache",".","The","main","thread","is","responsible","for","setting","the","flag","when","the","cache","size","reaches","a","defined","threshold","."]
code: def run(self):
      # We need a separate db connection per thread:
      try:
          self.db = sqlite3.connect(
              str(self.history_manager.hist_file),
              **self.history_manager.connection_options,
          )
          while True:
              self.history_manager.save_flag.wait()
              if self.stop_now:
                  self.db.close()
                  return
              self.history_manager.save_flag.clear()
              self.history_manager.writeout_cache(self.db)
      except Exception as e:
          print(
              (
                  "The history saving thread hit an unexpected error (%s)."
                  "History will not be written to the database."
              )
              % repr(e)
          )
  
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 2 for calling the HistorySavingThread obj's underlying member method code with example usage: obj.run() without return types