Write any entries in the cache to the database.
(self, conn: Optional[sqlite3.Connection] = None)
| 1065 | |
| 1066 | @only_when_enabled |
| 1067 | def writeout_cache(self, conn: Optional[sqlite3.Connection] = None) -> None: |
| 1068 | """Write any entries in the cache to the database.""" |
| 1069 | if conn is None: |
| 1070 | conn = self.db |
| 1071 | |
| 1072 | with self.db_input_cache_lock: |
| 1073 | try: |
| 1074 | self._writeout_input_cache(conn) |
| 1075 | except sqlite3.IntegrityError: |
| 1076 | self.new_session(conn) |
| 1077 | print( |
| 1078 | "ERROR! Session/line number was not unique in", |
| 1079 | "database. History logging moved to new session", |
| 1080 | self.session_number, |
| 1081 | ) |
| 1082 | try: |
| 1083 | # Try writing to the new session. If this fails, don't |
| 1084 | # recurse |
| 1085 | self._writeout_input_cache(conn) |
| 1086 | except sqlite3.IntegrityError: |
| 1087 | pass |
| 1088 | finally: |
| 1089 | self.db_input_cache = [] |
| 1090 | |
| 1091 | with self.db_output_cache_lock: |
| 1092 | try: |
| 1093 | self._writeout_output_cache(conn) |
| 1094 | except sqlite3.IntegrityError: |
| 1095 | print( |
| 1096 | "!! Session/line number for output was not unique", |
| 1097 | "in database. Output will not be stored.", |
| 1098 | ) |
| 1099 | finally: |
| 1100 | self.db_output_cache = [] |
| 1101 | |
| 1102 | |
| 1103 | if hasattr(os, "register_at_fork"): |