Show More
@@ -22,6 +22,7 b' import sqlite3' | |||
|
22 | 22 | import threading |
|
23 | 23 | |
|
24 | 24 | from collections import defaultdict |
|
25 | from contextlib import nested | |
|
25 | 26 | |
|
26 | 27 | # Our own packages |
|
27 | 28 | from IPython.config.configurable import Configurable |
@@ -127,6 +128,8 b' class HistoryManager(Configurable):' | |||
|
127 | 128 | raise |
|
128 | 129 | |
|
129 | 130 | self.save_flag = threading.Event() |
|
131 | self.db_input_cache_lock = threading.Lock() | |
|
132 | self.db_output_cache_lock = threading.Lock() | |
|
130 | 133 | self.save_thread = HistorySavingThread(self) |
|
131 | 134 | self.save_thread.start() |
|
132 | 135 | |
@@ -383,6 +386,7 b' class HistoryManager(Configurable):' | |||
|
383 | 386 | self.input_hist_parsed.append(source) |
|
384 | 387 | self.input_hist_raw.append(source_raw) |
|
385 | 388 | |
|
389 | with self.db_input_cache_lock: | |
|
386 | 390 | self.db_input_cache.append((line_num, source, source_raw)) |
|
387 | 391 | # Trigger to flush cache and write to DB. |
|
388 | 392 | if len(self.db_input_cache) >= self.db_cache_size: |
@@ -416,6 +420,7 b' class HistoryManager(Configurable):' | |||
|
416 | 420 | return |
|
417 | 421 | output = json.dumps(self.output_hist_reprs[line_num]) |
|
418 | 422 | |
|
423 | with self.db_output_cache_lock: | |
|
419 | 424 | self.db_output_cache.append((line_num, output)) |
|
420 | 425 | if self.db_cache_size <= 1: |
|
421 | 426 | self.save_flag.set() |
@@ -436,6 +441,8 b' class HistoryManager(Configurable):' | |||
|
436 | 441 | """Write any entries in the cache to the database.""" |
|
437 | 442 | if conn is None: |
|
438 | 443 | conn = self.db |
|
444 | ||
|
445 | with self.db_input_cache_lock: | |
|
439 | 446 | try: |
|
440 | 447 | self._writeout_input_cache(conn) |
|
441 | 448 | except sqlite3.IntegrityError: |
@@ -450,6 +457,7 b' class HistoryManager(Configurable):' | |||
|
450 | 457 | finally: |
|
451 | 458 | self.db_input_cache = [] |
|
452 | 459 | |
|
460 | with self.db_output_cache_lock: | |
|
453 | 461 | try: |
|
454 | 462 | self._writeout_output_cache(conn) |
|
455 | 463 | except sqlite3.IntegrityError: |
General Comments 0
You need to be logged in to leave comments.
Login now