Show More
@@ -3771,6 +3771,22 class InteractiveShell(SingletonConfigurable): | |||
|
3771 | 3771 | raise TypeError("%s is neither a string nor a macro." % target, |
|
3772 | 3772 | codeobj) |
|
3773 | 3773 | |
|
3774 | def _atexit_once(self): | |
|
3775 | """ | |
|
3776 | At exist operation that need to be called at most once. | |
|
3777 | Second call to this function per instance will do nothing. | |
|
3778 | """ | |
|
3779 | ||
|
3780 | if not getattr(self, "_atexit_once_called", False): | |
|
3781 | self._atexit_once_called = True | |
|
3782 | # Clear all user namespaces to release all references cleanly. | |
|
3783 | self.reset(new_session=False) | |
|
3784 | # Close the history session (this stores the end time and line count) | |
|
3785 | # this must be *before* the tempfile cleanup, in case of temporary | |
|
3786 | # history db | |
|
3787 | self.history_manager.end_session() | |
|
3788 | self.history_manager = None | |
|
3789 | ||
|
3774 | 3790 | #------------------------------------------------------------------------- |
|
3775 | 3791 | # Things related to IPython exiting |
|
3776 | 3792 | #------------------------------------------------------------------------- |
@@ -3785,13 +3801,7 class InteractiveShell(SingletonConfigurable): | |||
|
3785 | 3801 | code that has the appropriate information, rather than trying to |
|
3786 | 3802 | clutter |
|
3787 | 3803 | """ |
|
3788 | # Clear all user namespaces to release all references cleanly. | |
|
3789 | self.reset(new_session=False) | |
|
3790 | # Close the history session (this stores the end time and line count) | |
|
3791 | # this must be *before* the tempfile cleanup, in case of temporary | |
|
3792 | # history db | |
|
3793 | self.history_manager.end_session() | |
|
3794 | del self.history_manager | |
|
3804 | self._atexit_once() | |
|
3795 | 3805 | |
|
3796 | 3806 | # Cleanup all tempfiles and folders left around |
|
3797 | 3807 | for tfile in self.tempfiles: |
@@ -146,8 +146,16 def test_import_pylab(): | |||
|
146 | 146 | nt.assert_true('plt' in ns) |
|
147 | 147 | nt.assert_equal(ns['np'], np) |
|
148 | 148 | |
|
149 | from traitlets.config import Config | |
|
150 | ||
|
151 | ||
|
149 | 152 | class TestPylabSwitch(object): |
|
150 | 153 | class Shell(InteractiveShell): |
|
154 | def init_history(self): | |
|
155 | """Sets up the command history, and starts regular autosaves.""" | |
|
156 | self.config.HistoryManager.hist_file = ":memory:" | |
|
157 | super().init_history() | |
|
158 | ||
|
151 | 159 | def enable_gui(self, gui): |
|
152 | 160 | pass |
|
153 | 161 | |
@@ -179,6 +187,7 class TestPylabSwitch(object): | |||
|
179 | 187 | matplotlib.rcParamsOrig = self._saved_rcParamsOrig |
|
180 | 188 | |
|
181 | 189 | def test_qt(self): |
|
190 | ||
|
182 | 191 | s = self.Shell() |
|
183 | 192 | gui, backend = s.enable_matplotlib(None) |
|
184 | 193 | nt.assert_equal(gui, 'qt') |
@@ -615,6 +615,13 class TerminalInteractiveShell(InteractiveShell): | |||
|
615 | 615 | |
|
616 | 616 | self.restore_term_title() |
|
617 | 617 | |
|
618 | # try to call some at-exit operation optimistically as some things can't | |
|
619 | # be done during interpreter shutdown. this is technically inaccurate as | |
|
620 | # this make mainlool not re-callable, but that should be a rare if not | |
|
621 | # in existent use case. | |
|
622 | ||
|
623 | self._atexit_once() | |
|
624 | ||
|
618 | 625 | |
|
619 | 626 | _inputhook = None |
|
620 | 627 | def inputhook(self, context): |
General Comments 0
You need to be logged in to leave comments.
Login now