##// END OF EJS Templates
Changed autosave code.
Mani chandra -
Show More
@@ -17,6 +17,8 b' import fnmatch'
17 import json
17 import json
18 import os
18 import os
19 import sys
19 import sys
20 import threading
21 import time
20
22
21 # Our own packages
23 # Our own packages
22 import IPython.utils.io
24 import IPython.utils.io
@@ -251,6 +253,23 b' class HistoryManager(object):'
251 # The directory history can't be completely empty
253 # The directory history can't be completely empty
252 self.dir_hist[:] = [os.getcwd()]
254 self.dir_hist[:] = [os.getcwd()]
253
255
256 class HistorySaveThread(threading.Thread):
257 """Thread to save history periodically"""
258
259 def __init__(self, IPython_object, time_interval, exit_now):
260 threading.Thread.__init__(self)
261 self.IPython_object = IPython_object
262 self.time_interval = time_interval
263 self.exit_now = exit_now
264
265 def run(self):
266 while 1:
267 if self.exit_now==True:
268 break
269 time.sleep(self.time_interval)
270 #printing for debug
271 #print("Saving...")
272 self.IPython_object.save_history()
254
273
255 def magic_history(self, parameter_s = ''):
274 def magic_history(self, parameter_s = ''):
256 """Print input history (_i<n> variables), with most recent last.
275 """Print input history (_i<n> variables), with most recent last.
@@ -27,8 +27,6 b' import re'
27 import sys
27 import sys
28 import tempfile
28 import tempfile
29 import types
29 import types
30 import threading
31 import time
32 from contextlib import nested
30 from contextlib import nested
33
31
34 from IPython.config.configurable import Configurable
32 from IPython.config.configurable import Configurable
@@ -47,6 +45,7 b' from IPython.core.error import TryNext, UsageError'
47 from IPython.core.extensions import ExtensionManager
45 from IPython.core.extensions import ExtensionManager
48 from IPython.core.fakemodule import FakeModule, init_fakemod_dict
46 from IPython.core.fakemodule import FakeModule, init_fakemod_dict
49 from IPython.core.history import HistoryManager
47 from IPython.core.history import HistoryManager
48 from IPython.core.history import HistorySaveThread
50 from IPython.core.inputsplitter import IPythonInputSplitter
49 from IPython.core.inputsplitter import IPythonInputSplitter
51 from IPython.core.logger import Logger
50 from IPython.core.logger import Logger
52 from IPython.core.magic import Magic
51 from IPython.core.magic import Magic
@@ -131,23 +130,6 b' class SeparateStr(Str):'
131 class MultipleInstanceError(Exception):
130 class MultipleInstanceError(Exception):
132 pass
131 pass
133
132
134 class HistorySaveThread(threading.Thread):
135 """Thread to save history periodically"""
136
137 def __init__(self, IPython_object, time_interval, exit_now):
138 threading.Thread.__init__(self)
139 self.IPython_object = IPython_object
140 self.time_interval = time_interval
141 self.exit_now = exit_now
142
143 def run(self):
144 while 1:
145 if self.exit_now==True:
146 break
147 time.sleep(self.time_interval)
148 #printing for debug
149 #print "Saving..."
150 self.IPython_object.save_history()
151
133
152 #-----------------------------------------------------------------------------
134 #-----------------------------------------------------------------------------
153 # Main IPython class
135 # Main IPython class
@@ -312,7 +294,7 b' class InteractiveShell(Configurable, Magic):'
312 self.init_payload()
294 self.init_payload()
313 self.hooks.late_startup_hook()
295 self.hooks.late_startup_hook()
314 atexit.register(self.atexit_operations)
296 atexit.register(self.atexit_operations)
315 self.history_thread = HistorySaveThread(self, 1, False)
297 self.history_thread = HistorySaveThread(self, 10, False)
316 self.history_thread.start()
298 self.history_thread.start()
317
299
318 # 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
@@ -24,7 +24,7 b' import sys'
24 from IPython.core.error import TryNext
24 from IPython.core.error import TryNext
25 from IPython.core.usage import interactive_usage, default_banner
25 from IPython.core.usage import interactive_usage, default_banner
26 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
26 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
27 from IPython.core.interactiveshell import HistorySaveThread
27 from IPython.core.history import HistorySaveThread
28 from IPython.lib.inputhook import enable_gui
28 from IPython.lib.inputhook import enable_gui
29 from IPython.lib.pylabtools import pylab_activate
29 from IPython.lib.pylabtools import pylab_activate
30 from IPython.utils.terminal import toggle_set_term_title, set_term_title
30 from IPython.utils.terminal import toggle_set_term_title, set_term_title
@@ -497,16 +497,13 b' class TerminalInteractiveShell(InteractiveShell):'
497 """Handle interactive exit.
497 """Handle interactive exit.
498
498
499 This method calls the ask_exit callback."""
499 This method calls the ask_exit callback."""
500 self.shell.history_thread.exit_now=True
501 self.shell.history_thread.join()
502 if self.confirm_exit:
500 if self.confirm_exit:
503 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
504 self.ask_exit()
503 self.ask_exit()
505 else:
506 self.shell.history_thread = HistorySaveThread(self.shell, 1,
507 False)
508 self.shell.history_thread.start()
509 else:
504 else:
505 self.shell.history_thread = HistorySaveThread(self.shell, 10, False)
506 self.shell.history_thread.start()
510 self.ask_exit()
507 self.ask_exit()
511
508
512 #------------------------------------------------------------------------
509 #------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now