Show More
@@ -6,15 +6,12 b'' | |||
|
6 | 6 | |
|
7 | 7 | import atexit |
|
8 | 8 | import datetime |
|
9 | from pathlib import Path | |
|
10 | 9 | import re |
|
11 | 10 | import sqlite3 |
|
12 | 11 | import threading |
|
12 | from pathlib import Path | |
|
13 | 13 | |
|
14 | from traitlets.config.configurable import LoggingConfigurable | |
|
15 | 14 | from decorator import decorator |
|
16 | from IPython.utils.decorators import undoc | |
|
17 | from IPython.paths import locate_profile | |
|
18 | 15 | from traitlets import ( |
|
19 | 16 | Any, |
|
20 | 17 | Bool, |
@@ -22,12 +19,16 b' from traitlets import (' | |||
|
22 | 19 | Instance, |
|
23 | 20 | Integer, |
|
24 | 21 | List, |
|
22 | TraitError, | |
|
25 | 23 | Unicode, |
|
26 | 24 | Union, |
|
27 | TraitError, | |
|
28 | 25 | default, |
|
29 | 26 | observe, |
|
30 | 27 | ) |
|
28 | from traitlets.config.configurable import LoggingConfigurable | |
|
29 | ||
|
30 | from IPython.paths import locate_profile | |
|
31 | from IPython.utils.decorators import undoc | |
|
31 | 32 | |
|
32 | 33 | #----------------------------------------------------------------------------- |
|
33 | 34 | # Classes and functions |
@@ -554,7 +555,14 b' class HistoryManager(HistoryAccessor):' | |||
|
554 | 555 | |
|
555 | 556 | if self.enabled and self.hist_file != ':memory:': |
|
556 | 557 | self.save_thread = HistorySavingThread(self) |
|
558 | try: | |
|
557 | 559 | self.save_thread.start() |
|
560 | except RuntimeError: | |
|
561 | self.log.error( | |
|
562 | "Failed to start history saving thread. History will not be saved.", | |
|
563 | exc_info=True, | |
|
564 | ) | |
|
565 | self.hist_file = ":memory:" | |
|
558 | 566 | |
|
559 | 567 | def _get_hist_file_name(self, profile=None): |
|
560 | 568 | """Get default history file name based on the Shell's profile. |
@@ -880,10 +888,10 b' class HistorySavingThread(threading.Thread):' | |||
|
880 | 888 | super(HistorySavingThread, self).__init__(name="IPythonHistorySavingThread") |
|
881 | 889 | self.history_manager = history_manager |
|
882 | 890 | self.enabled = history_manager.enabled |
|
883 | atexit.register(self.stop) | |
|
884 | 891 | |
|
885 | 892 | @only_when_enabled |
|
886 | 893 | def run(self): |
|
894 | atexit.register(self.stop) | |
|
887 | 895 | # We need a separate db connection per thread: |
|
888 | 896 | try: |
|
889 | 897 | self.db = sqlite3.connect( |
@@ -900,6 +908,8 b' class HistorySavingThread(threading.Thread):' | |||
|
900 | 908 | except Exception as e: |
|
901 | 909 | print(("The history saving thread hit an unexpected error (%s)." |
|
902 | 910 | "History will not be written to the database.") % repr(e)) |
|
911 | finally: | |
|
912 | atexit.unregister(self.stop) | |
|
903 | 913 | |
|
904 | 914 | def stop(self): |
|
905 | 915 | """This can be called from the main thread to safely stop this thread. |
General Comments 0
You need to be logged in to leave comments.
Login now