Show More
@@ -56,7 +56,7 b' class DummyDB(object):' | |||||
56 | @decorator |
|
56 | @decorator | |
57 | def needs_sqlite(f, self, *a, **kw): |
|
57 | def needs_sqlite(f, self, *a, **kw): | |
58 | """return an empty list in the absence of sqlite""" |
|
58 | """return an empty list in the absence of sqlite""" | |
59 |
if sqlite3 is None or self. |
|
59 | if sqlite3 is None or not self.enabled: | |
60 | return [] |
|
60 | return [] | |
61 | else: |
|
61 | else: | |
62 | return f(self, *a, **kw) |
|
62 | return f(self, *a, **kw) | |
@@ -84,10 +84,11 b' class HistoryAccessor(Configurable):' | |||||
84 |
|
84 | |||
85 | """) |
|
85 | """) | |
86 |
|
86 | |||
87 |
|
|
87 | enabled = Bool(True, config=True, | |
88 |
help=""" |
|
88 | help="""enable the SQLite history | |
89 |
|
89 | |||
90 | If True there will be no stored history, no SQLite connection, |
|
90 | set enabled=False to disable the SQLite history, | |
|
91 | in which case there will be no stored history, no SQLite connection, | |||
91 | and no background saving thread. This may be necessary in some |
|
92 | and no background saving thread. This may be necessary in some | |
92 | threaded environments where IPython is embedded. |
|
93 | threaded environments where IPython is embedded. | |
93 | """ |
|
94 | """ | |
@@ -135,9 +136,9 b' class HistoryAccessor(Configurable):' | |||||
135 | # No one has set the hist_file, yet. |
|
136 | # No one has set the hist_file, yet. | |
136 | self.hist_file = self._get_hist_file_name(profile) |
|
137 | self.hist_file = self._get_hist_file_name(profile) | |
137 |
|
138 | |||
138 |
if sqlite3 is None and |
|
139 | if sqlite3 is None and self.enabled: | |
139 | warn("IPython History requires SQLite, your history will not be saved\n") |
|
140 | warn("IPython History requires SQLite, your history will not be saved\n") | |
140 |
self. |
|
141 | self.enabled = False | |
141 |
|
142 | |||
142 | if sqlite3 is not None: |
|
143 | if sqlite3 is not None: | |
143 | DatabaseError = sqlite3.DatabaseError |
|
144 | DatabaseError = sqlite3.DatabaseError | |
@@ -174,7 +175,7 b' class HistoryAccessor(Configurable):' | |||||
174 |
|
175 | |||
175 | def init_db(self): |
|
176 | def init_db(self): | |
176 | """Connect to the database, and create tables if necessary.""" |
|
177 | """Connect to the database, and create tables if necessary.""" | |
177 |
if self. |
|
178 | if not self.enabled: | |
178 | self.db = DummyDB() |
|
179 | self.db = DummyDB() | |
179 | return |
|
180 | return | |
180 |
|
181 | |||
@@ -433,7 +434,7 b' class HistoryManager(HistoryAccessor):' | |||||
433 | self.save_flag = threading.Event() |
|
434 | self.save_flag = threading.Event() | |
434 | self.db_input_cache_lock = threading.Lock() |
|
435 | self.db_input_cache_lock = threading.Lock() | |
435 | self.db_output_cache_lock = threading.Lock() |
|
436 | self.db_output_cache_lock = threading.Lock() | |
436 |
if |
|
437 | if self.enabled and self.hist_file != ':memory:': | |
437 | self.save_thread = HistorySavingThread(self) |
|
438 | self.save_thread = HistorySavingThread(self) | |
438 | self.save_thread.start() |
|
439 | self.save_thread.start() | |
439 |
|
440 | |||
@@ -669,11 +670,11 b' class HistorySavingThread(threading.Thread):' | |||||
669 | the cache size reaches a defined threshold.""" |
|
670 | the cache size reaches a defined threshold.""" | |
670 | daemon = True |
|
671 | daemon = True | |
671 | stop_now = False |
|
672 | stop_now = False | |
672 |
|
|
673 | enabled = True | |
673 | def __init__(self, history_manager): |
|
674 | def __init__(self, history_manager): | |
674 | super(HistorySavingThread, self).__init__() |
|
675 | super(HistorySavingThread, self).__init__() | |
675 | self.history_manager = history_manager |
|
676 | self.history_manager = history_manager | |
676 |
self. |
|
677 | self.enabled = history_manager.enabled | |
677 | atexit.register(self.stop) |
|
678 | atexit.register(self.stop) | |
678 |
|
679 | |||
679 | @needs_sqlite |
|
680 | @needs_sqlite |
General Comments 0
You need to be logged in to leave comments.
Login now