##// END OF EJS Templates
Add history autosave thread to atexit cleanup, so that the tests don't produce nasty thread exceptions.
Thomas Kluyver -
Show More
@@ -257,29 +257,24 b' class HistorySaveThread(threading.Thread):'
257 """Thread to save history periodically"""
257 """Thread to save history periodically"""
258 daemon = True
258 daemon = True
259
259
260 def __init__(self, IPython_object, time_interval, exit_now):
260 def __init__(self, IPython_object, time_interval):
261 threading.Thread.__init__(self)
261 threading.Thread.__init__(self)
262 self.IPython_object = IPython_object
262 self.IPython_object = IPython_object
263 self.time_interval = time_interval
263 self.time_interval = time_interval
264 self.exit_now = exit_now
264 self.exit_now = threading.Event()
265 self.cond = threading.Condition()
266
265
267 def run(self):
266 def run(self):
268 while 1:
267 while True:
269 self.cond.acquire()
268 self.exit_now.wait(self.time_interval)
270 self.cond.wait(self.time_interval)
269 if self.exit_now.is_set():
271 self.cond.release()
272 if self.exit_now==True:
273 break
270 break
274 #printing for debug
271 #printing for debug
275 #print("Saving...")
272 #print("Saving...")
276 self.IPython_object.save_history()
273 self.IPython_object.save_history()
277
274
278 def stop(self):
275 def stop(self):
279 self.exit_now=True
276 self.exit_now.set()
280 self.cond.acquire()
277 self.join()
281 self.cond.notify()
282 self.cond.release()
283
278
284 def magic_history(self, parameter_s = ''):
279 def magic_history(self, parameter_s = ''):
285 """Print input history (_i<n> variables), with most recent last.
280 """Print input history (_i<n> variables), with most recent last.
@@ -294,7 +294,7 b' class InteractiveShell(Configurable, Magic):'
294 self.init_payload()
294 self.init_payload()
295 self.hooks.late_startup_hook()
295 self.hooks.late_startup_hook()
296 atexit.register(self.atexit_operations)
296 atexit.register(self.atexit_operations)
297 self.history_thread = HistorySaveThread(self, 60, False)
297 self.history_thread = HistorySaveThread(self, 60)
298 self.history_thread.start()
298 self.history_thread.start()
299
299
300 # While we're trying to have each part of the code directly access what it
300 # While we're trying to have each part of the code directly access what it
@@ -2526,6 +2526,7 b' class InteractiveShell(Configurable, Magic):'
2526 except OSError:
2526 except OSError:
2527 pass
2527 pass
2528
2528
2529 self.history_thread.stop()
2529 self.save_history()
2530 self.save_history()
2530
2531
2531 # Clear all user namespaces to release all references cleanly.
2532 # Clear all user namespaces to release all references cleanly.
General Comments 0
You need to be logged in to leave comments. Login now