Write any entries in the cache to the database.
(self, conn=None)
| 771 | |
| 772 | @needs_sqlite |
| 773 | def writeout_cache(self, conn=None): |
| 774 | """Write any entries in the cache to the database.""" |
| 775 | if conn is None: |
| 776 | conn = self.db |
| 777 | |
| 778 | with self.db_input_cache_lock: |
| 779 | try: |
| 780 | self._writeout_input_cache(conn) |
| 781 | except sqlite3.IntegrityError: |
| 782 | self.new_session(conn) |
| 783 | print("ERROR! Session/line number was not unique in", |
| 784 | "database. History logging moved to new session", |
| 785 | self.session_number) |
| 786 | try: |
| 787 | # Try writing to the new session. If this fails, don't |
| 788 | # recurse |
| 789 | self._writeout_input_cache(conn) |
| 790 | except sqlite3.IntegrityError: |
| 791 | pass |
| 792 | finally: |
| 793 | self.db_input_cache = [] |
| 794 | |
| 795 | with self.db_output_cache_lock: |
| 796 | try: |
| 797 | self._writeout_output_cache(conn) |
| 798 | except sqlite3.IntegrityError: |
| 799 | print("!! Session/line number for output was not unique", |
| 800 | "in database. Output will not be stored.") |
| 801 | finally: |
| 802 | self.db_output_cache = [] |
| 803 | |
| 804 | |
| 805 | class HistorySavingThread(threading.Thread): |