##// 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 class HistorySavingThread(threading.Thread):
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 daemon = True
480 daemon = True
475 stop_now = False
481 stop_now = False
476 def __init__(self, history_manager):
482 def __init__(self, history_manager):
@@ -483,14 +489,20 b' class HistorySavingThread(threading.Thread):'
483 self.db = sqlite3.connect(self.history_manager.hist_file)
489 self.db = sqlite3.connect(self.history_manager.hist_file)
484 while True:
490 while True:
485 self.history_manager.save_flag.wait()
491 self.history_manager.save_flag.wait()
486 self.history_manager.save_flag.clear()
487 self.history_manager.writeout_cache(self.db)
488 if self.stop_now:
492 if self.stop_now:
489 return
493 return
494 self.history_manager.save_flag.clear()
495 self.history_manager.writeout_cache(self.db)
490
496
491 def stop(self):
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 self.stop_now = True
503 self.stop_now = True
493 self.history_manager.save_flag.set()
504 self.history_manager.save_flag.set()
505 self.join()
494
506
495
507
496 # To match, e.g. ~5/8-~2/3
508 # To match, e.g. ~5/8-~2/3
General Comments 0
You need to be logged in to leave comments. Login now