diff --git a/IPython/core/history.py b/IPython/core/history.py index 6438469..4f40c04 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -257,29 +257,24 @@ class HistorySaveThread(threading.Thread): """Thread to save history periodically""" daemon = True - def __init__(self, IPython_object, time_interval, exit_now): + def __init__(self, IPython_object, time_interval): threading.Thread.__init__(self) self.IPython_object = IPython_object self.time_interval = time_interval - self.exit_now = exit_now - self.cond = threading.Condition() + self.exit_now = threading.Event() def run(self): - while 1: - self.cond.acquire() - self.cond.wait(self.time_interval) - self.cond.release() - if self.exit_now==True: + while True: + self.exit_now.wait(self.time_interval) + if self.exit_now.is_set(): break #printing for debug #print("Saving...") self.IPython_object.save_history() def stop(self): - self.exit_now=True - self.cond.acquire() - self.cond.notify() - self.cond.release() + self.exit_now.set() + self.join() def magic_history(self, parameter_s = ''): """Print input history (_i variables), with most recent last. diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index d1b2108..b6c8c5b 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -294,7 +294,7 @@ class InteractiveShell(Configurable, Magic): self.init_payload() self.hooks.late_startup_hook() atexit.register(self.atexit_operations) - self.history_thread = HistorySaveThread(self, 60, False) + 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 @@ -2526,6 +2526,7 @@ class InteractiveShell(Configurable, Magic): except OSError: pass + self.history_thread.stop() self.save_history() # Clear all user namespaces to release all references cleanly.