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