##// END OF EJS Templates
Add docstrings, improve history thread stop method.
Thomas Kluyver -
Show More
@@ -471,6 +471,12 b' class HistoryManager(Configurable):'
471 471
472 472
473 473 class HistorySavingThread(threading.Thread):
474 """This thread takes care of writing history to the database, so that
475 the UI isn't held up while that happens.
476
477 It waits for the HistoryManager's save_flag to be set, then writes out
478 the history cache. The main thread is responsible for setting the flag when
479 the cache size reaches a defined threshold."""
474 480 daemon = True
475 481 stop_now = False
476 482 def __init__(self, history_manager):
@@ -483,14 +489,20 b' class HistorySavingThread(threading.Thread):'
483 489 self.db = sqlite3.connect(self.history_manager.hist_file)
484 490 while True:
485 491 self.history_manager.save_flag.wait()
486 self.history_manager.save_flag.clear()
487 self.history_manager.writeout_cache(self.db)
488 492 if self.stop_now:
489 493 return
494 self.history_manager.save_flag.clear()
495 self.history_manager.writeout_cache(self.db)
490 496
491 497 def stop(self):
498 """This can be called from the main thread to safely stop this thread.
499
500 Note that it does not attempt to write out remaining history before
501 exiting. That should be done by calling the HistoryManager's
502 end_session method."""
492 503 self.stop_now = True
493 504 self.history_manager.save_flag.set()
505 self.join()
494 506
495 507
496 508 # To match, e.g. ~5/8-~2/3
General Comments 0
You need to be logged in to leave comments. Login now