diff --git a/IPython/core/history.py b/IPython/core/history.py index 4f40c04..469047e 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -254,10 +254,13 @@ class HistoryManager(object): self.dir_hist[:] = [os.getcwd()] class HistorySaveThread(threading.Thread): - """Thread to save history periodically""" + """This thread saves history periodically (the current default is once per + minute), so that it is not lost in the event of a crash. It also allows the + commands in the current IPython shell to be accessed in a newly started + instance.""" daemon = True - def __init__(self, IPython_object, time_interval): + def __init__(self, IPython_object, time_interval=60): threading.Thread.__init__(self) self.IPython_object = IPython_object self.time_interval = time_interval @@ -268,11 +271,12 @@ class HistorySaveThread(threading.Thread): self.exit_now.wait(self.time_interval) if self.exit_now.is_set(): break - #printing for debug - #print("Saving...") + #print("Autosaving history...") # DEBUG self.IPython_object.save_history() def stop(self): + """Safely and quickly stop the autosave thread. This will not cause the + history to be saved before stopping.""" self.exit_now.set() self.join() diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index b6c8c5b..0bfdaa3 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -294,8 +294,6 @@ class InteractiveShell(Configurable, Magic): self.init_payload() self.hooks.late_startup_hook() atexit.register(self.atexit_operations) - self.history_thread = HistorySaveThread(self, 60) - self.history_thread.start() # While we're trying to have each part of the code directly access what it # needs without keeping redundant references to objects, we have too much @@ -1238,7 +1236,10 @@ class InteractiveShell(Configurable, Magic): #------------------------------------------------------------------------- def init_history(self): + """Sets up the command history, and starts regular autosaves.""" self.history_manager = HistoryManager(shell=self) + self.history_thread = HistorySaveThread(self, time_interval=60) + self.history_thread.start() def save_history(self): """Save input history to a file (via readline library)."""