##// END OF EJS Templates
Improved autosave code. Autosave thread termination is instantaneous.
Mani chandra -
Show More
@@ -261,14 +261,17 b' class HistorySaveThread(threading.Thread):'
261 self.IPython_object = IPython_object
261 self.IPython_object = IPython_object
262 self.time_interval = time_interval
262 self.time_interval = time_interval
263 self.exit_now = exit_now
263 self.exit_now = exit_now
264 self.cond = threading.Condition()
264
265
265 def run(self):
266 def run(self):
266 while 1:
267 while 1:
268 self.cond.acquire()
269 self.cond.wait(self.time_interval)
270 self.cond.release()
267 if self.exit_now==True:
271 if self.exit_now==True:
268 break
272 break
269 time.sleep(self.time_interval)
270 #printing for debug
273 #printing for debug
271 #print("Saving...")
274 print("Saving...")
272 self.IPython_object.save_history()
275 self.IPython_object.save_history()
273
276
274 def magic_history(self, parameter_s = ''):
277 def magic_history(self, parameter_s = ''):
@@ -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, 10, False)
297 self.history_thread = HistorySaveThread(self, 60, False)
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
@@ -500,9 +500,12 b' class TerminalInteractiveShell(InteractiveShell):'
500 if self.confirm_exit:
500 if self.confirm_exit:
501 if self.ask_yes_no('Do you really want to exit ([y]/n)?','y'):
501 if self.ask_yes_no('Do you really want to exit ([y]/n)?','y'):
502 self.shell.history_thread.exit_now=True
502 self.shell.history_thread.exit_now=True
503 self.shell.history_thread.cond.acquire()
504 self.shell.history_thread.cond.notify()
505 self.shell.history_thread.cond.release()
503 self.ask_exit()
506 self.ask_exit()
504 else:
507 else:
505 self.shell.history_thread = HistorySaveThread(self.shell, 10, False)
508 self.shell.history_thread = HistorySaveThread(self.shell, 60, False)
506 self.shell.history_thread.start()
509 self.shell.history_thread.start()
507 self.ask_exit()
510 self.ask_exit()
508
511
General Comments 0
You need to be logged in to leave comments. Login now