Show More
@@ -254,10 +254,13 class HistoryManager(object): | |||||
254 | self.dir_hist[:] = [os.getcwd()] |
|
254 | self.dir_hist[:] = [os.getcwd()] | |
255 |
|
255 | |||
256 | class HistorySaveThread(threading.Thread): |
|
256 | class HistorySaveThread(threading.Thread): | |
257 |
"""Thread |
|
257 | """This thread saves history periodically (the current default is once per | |
|
258 | minute), so that it is not lost in the event of a crash. It also allows the | |||
|
259 | commands in the current IPython shell to be accessed in a newly started | |||
|
260 | instance.""" | |||
258 | daemon = True |
|
261 | daemon = True | |
259 |
|
262 | |||
260 | def __init__(self, IPython_object, time_interval): |
|
263 | def __init__(self, IPython_object, time_interval=60): | |
261 | threading.Thread.__init__(self) |
|
264 | threading.Thread.__init__(self) | |
262 | self.IPython_object = IPython_object |
|
265 | self.IPython_object = IPython_object | |
263 | self.time_interval = time_interval |
|
266 | self.time_interval = time_interval | |
@@ -268,11 +271,12 class HistorySaveThread(threading.Thread): | |||||
268 | self.exit_now.wait(self.time_interval) |
|
271 | self.exit_now.wait(self.time_interval) | |
269 | if self.exit_now.is_set(): |
|
272 | if self.exit_now.is_set(): | |
270 | break |
|
273 | break | |
271 | #printing for debug |
|
274 | #print("Autosaving history...") # DEBUG | |
272 | #print("Saving...") |
|
|||
273 | self.IPython_object.save_history() |
|
275 | self.IPython_object.save_history() | |
274 |
|
276 | |||
275 | def stop(self): |
|
277 | def stop(self): | |
|
278 | """Safely and quickly stop the autosave thread. This will not cause the | |||
|
279 | history to be saved before stopping.""" | |||
276 | self.exit_now.set() |
|
280 | self.exit_now.set() | |
277 | self.join() |
|
281 | self.join() | |
278 |
|
282 |
@@ -294,8 +294,6 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) |
|
|||
298 | self.history_thread.start() |
|
|||
299 |
|
297 | |||
300 | # While we're trying to have each part of the code directly access what it |
|
298 | # While we're trying to have each part of the code directly access what it | |
301 | # needs without keeping redundant references to objects, we have too much |
|
299 | # needs without keeping redundant references to objects, we have too much | |
@@ -1238,7 +1236,10 class InteractiveShell(Configurable, Magic): | |||||
1238 | #------------------------------------------------------------------------- |
|
1236 | #------------------------------------------------------------------------- | |
1239 |
|
1237 | |||
1240 | def init_history(self): |
|
1238 | def init_history(self): | |
|
1239 | """Sets up the command history, and starts regular autosaves.""" | |||
1241 | self.history_manager = HistoryManager(shell=self) |
|
1240 | self.history_manager = HistoryManager(shell=self) | |
|
1241 | self.history_thread = HistorySaveThread(self, time_interval=60) | |||
|
1242 | self.history_thread.start() | |||
1242 |
|
1243 | |||
1243 | def save_history(self): |
|
1244 | def save_history(self): | |
1244 | """Save input history to a file (via readline library).""" |
|
1245 | """Save input history to a file (via readline library).""" |
General Comments 0
You need to be logged in to leave comments.
Login now