Show More
@@ -17,6 +17,8 b' import fnmatch' | |||
|
17 | 17 | import json |
|
18 | 18 | import os |
|
19 | 19 | import sys |
|
20 | import threading | |
|
21 | import time | |
|
20 | 22 | |
|
21 | 23 | # Our own packages |
|
22 | 24 | import IPython.utils.io |
@@ -251,6 +253,23 b' class HistoryManager(object):' | |||
|
251 | 253 | # The directory history can't be completely empty |
|
252 | 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 | 274 | def magic_history(self, parameter_s = ''): |
|
256 | 275 | """Print input history (_i<n> variables), with most recent last. |
@@ -27,8 +27,6 b' import re' | |||
|
27 | 27 | import sys |
|
28 | 28 | import tempfile |
|
29 | 29 | import types |
|
30 | import threading | |
|
31 | import time | |
|
32 | 30 | from contextlib import nested |
|
33 | 31 | |
|
34 | 32 | from IPython.config.configurable import Configurable |
@@ -47,6 +45,7 b' from IPython.core.error import TryNext, UsageError' | |||
|
47 | 45 | from IPython.core.extensions import ExtensionManager |
|
48 | 46 | from IPython.core.fakemodule import FakeModule, init_fakemod_dict |
|
49 | 47 | from IPython.core.history import HistoryManager |
|
48 | from IPython.core.history import HistorySaveThread | |
|
50 | 49 | from IPython.core.inputsplitter import IPythonInputSplitter |
|
51 | 50 | from IPython.core.logger import Logger |
|
52 | 51 | from IPython.core.magic import Magic |
@@ -131,23 +130,6 b' class SeparateStr(Str):' | |||
|
131 | 130 | class MultipleInstanceError(Exception): |
|
132 | 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 | 135 | # Main IPython class |
@@ -312,7 +294,7 b' class InteractiveShell(Configurable, Magic):' | |||
|
312 | 294 | self.init_payload() |
|
313 | 295 | self.hooks.late_startup_hook() |
|
314 | 296 | atexit.register(self.atexit_operations) |
|
315 | self.history_thread = HistorySaveThread(self, 1, False) | |
|
297 | self.history_thread = HistorySaveThread(self, 10, False) | |
|
316 | 298 | self.history_thread.start() |
|
317 | 299 | |
|
318 | 300 | # While we're trying to have each part of the code directly access what it |
@@ -24,7 +24,7 b' import sys' | |||
|
24 | 24 | from IPython.core.error import TryNext |
|
25 | 25 | from IPython.core.usage import interactive_usage, default_banner |
|
26 | 26 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
27 |
from IPython.core. |
|
|
27 | from IPython.core.history import HistorySaveThread | |
|
28 | 28 | from IPython.lib.inputhook import enable_gui |
|
29 | 29 | from IPython.lib.pylabtools import pylab_activate |
|
30 | 30 | from IPython.utils.terminal import toggle_set_term_title, set_term_title |
@@ -497,16 +497,13 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
497 | 497 | """Handle interactive exit. |
|
498 | 498 | |
|
499 | 499 | This method calls the ask_exit callback.""" |
|
500 | self.shell.history_thread.exit_now=True | |
|
501 | self.shell.history_thread.join() | |
|
502 | 500 | if self.confirm_exit: |
|
503 | 501 | if self.ask_yes_no('Do you really want to exit ([y]/n)?','y'): |
|
502 | self.shell.history_thread.exit_now=True | |
|
504 | 503 | self.ask_exit() |
|
505 | 504 |
|
|
506 |
|
|
|
507 | False) | |
|
505 | self.shell.history_thread = HistorySaveThread(self.shell, 10, False) | |
|
508 | 506 |
|
|
509 | else: | |
|
510 | 507 | self.ask_exit() |
|
511 | 508 | |
|
512 | 509 | #------------------------------------------------------------------------ |
General Comments 0
You need to be logged in to leave comments.
Login now