Show More
@@ -27,6 +27,8 b' import re' | |||
|
27 | 27 | import sys |
|
28 | 28 | import tempfile |
|
29 | 29 | import types |
|
30 | import threading | |
|
31 | import time | |
|
30 | 32 | from contextlib import nested |
|
31 | 33 | |
|
32 | 34 | from IPython.config.configurable import Configurable |
@@ -129,6 +131,23 b' class SeparateStr(Str):' | |||
|
129 | 131 | class MultipleInstanceError(Exception): |
|
130 | 132 | pass |
|
131 | 133 | |
|
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() | |
|
132 | 151 | |
|
133 | 152 | #----------------------------------------------------------------------------- |
|
134 | 153 | # Main IPython class |
@@ -293,6 +312,8 b' class InteractiveShell(Configurable, Magic):' | |||
|
293 | 312 | self.init_payload() |
|
294 | 313 | self.hooks.late_startup_hook() |
|
295 | 314 | atexit.register(self.atexit_operations) |
|
315 | self.history_thread = HistorySaveThread(self, 1, False) | |
|
316 | self.history_thread.start() | |
|
296 | 317 | |
|
297 | 318 | # While we're trying to have each part of the code directly access what it |
|
298 | 319 | # needs without keeping redundant references to objects, we have too much |
@@ -2523,7 +2544,6 b' class InteractiveShell(Configurable, Magic):' | |||
|
2523 | 2544 | except OSError: |
|
2524 | 2545 | pass |
|
2525 | 2546 | |
|
2526 | ||
|
2527 | 2547 | self.save_history() |
|
2528 | 2548 | |
|
2529 | 2549 | # Clear all user namespaces to release all references cleanly. |
@@ -24,6 +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.interactiveshell import HistorySaveThread | |
|
27 | 28 | from IPython.lib.inputhook import enable_gui |
|
28 | 29 | from IPython.lib.pylabtools import pylab_activate |
|
29 | 30 | from IPython.utils.terminal import toggle_set_term_title, set_term_title |
@@ -496,9 +497,15 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
496 | 497 | """Handle interactive exit. |
|
497 | 498 | |
|
498 | 499 | This method calls the ask_exit callback.""" |
|
500 | self.shell.history_thread.exit_now=True | |
|
501 | self.shell.history_thread.join() | |
|
499 | 502 | if self.confirm_exit: |
|
500 | 503 | if self.ask_yes_no('Do you really want to exit ([y]/n)?','y'): |
|
501 | 504 | self.ask_exit() |
|
505 | else: | |
|
506 | self.shell.history_thread = HistorySaveThread(self.shell, 1, | |
|
507 | False) | |
|
508 | self.shell.history_thread.start() | |
|
502 | 509 | else: |
|
503 | 510 | self.ask_exit() |
|
504 | 511 |
General Comments 0
You need to be logged in to leave comments.
Login now