diff --git a/IPython/core/history.py b/IPython/core/history.py index da10813..c9b8435 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -775,6 +775,7 @@ class HistorySavingThread(threading.Thread): while True: self.history_manager.save_flag.wait() if self.stop_now: + self.db.close() return self.history_manager.save_flag.clear() self.history_manager.writeout_cache(self.db) diff --git a/IPython/core/tests/test_history.py b/IPython/core/tests/test_history.py index 1ec2852..c08156b 100644 --- a/IPython/core/tests/test_history.py +++ b/IPython/core/tests/test_history.py @@ -136,6 +136,8 @@ def test_history(): finally: # Ensure saving thread is shut down before we try to clean up the files ip.history_manager.save_thread.stop() + # Forcibly close database rather than relying on garbage collection + ip.history_manager.db.close() # Restore history manager ip.history_manager = hist_manager_ori