Show More
@@ -319,6 +319,9 b' class DisplayHook(Configurable):' | |||
|
319 | 319 | except: pass |
|
320 | 320 | self.shell.user_ns['_oh'].clear() |
|
321 | 321 | |
|
322 | # Release our own references to objects: | |
|
323 | self._, self.__, self.___ = '', '', '' | |
|
324 | ||
|
322 | 325 | if '_' not in __builtin__.__dict__: |
|
323 | 326 | self.shell.user_ns.update({'_':None,'__':None, '___':None}) |
|
324 | 327 | import gc |
@@ -1045,6 +1045,9 b' class InteractiveShell(Configurable, Magic):' | |||
|
1045 | 1045 | """ |
|
1046 | 1046 | # Clear histories |
|
1047 | 1047 | self.history_manager.reset(new_session) |
|
1048 | ||
|
1049 | # Flush cached output items | |
|
1050 | self.displayhook.flush() | |
|
1048 | 1051 | |
|
1049 | 1052 | # Reset counter used to index all histories |
|
1050 | 1053 | self.execution_count = 0 |
@@ -1069,6 +1072,10 b' class InteractiveShell(Configurable, Magic):' | |||
|
1069 | 1072 | # Restore the default and user aliases |
|
1070 | 1073 | self.alias_manager.clear_aliases() |
|
1071 | 1074 | self.alias_manager.init_aliases() |
|
1075 | ||
|
1076 | # Flush the private list of module references kept for script | |
|
1077 | # execution protection | |
|
1078 | self.clear_main_mod_cache() | |
|
1072 | 1079 | |
|
1073 | 1080 | def reset_selective(self, regex=None): |
|
1074 | 1081 | """Clear selective variables from internal namespaces based on a |
@@ -967,12 +967,15 b' Currently the magic system has the following functions:\\n"""' | |||
|
967 | 967 | def magic_reset(self, parameter_s=''): |
|
968 | 968 | """Resets the namespace by removing all names defined by the user. |
|
969 | 969 | |
|
970 | Input/Output history are left around in case you need them. | |
|
971 | ||
|
972 | 970 | Parameters |
|
973 | 971 | ---------- |
|
974 | 972 | -f : force reset without asking for confirmation. |
|
975 | ||
|
973 | ||
|
974 | -s : 'Soft' reset: Only clears your namespace, leaving history intact. | |
|
975 | References to objects may be kept. By default (without this option), | |
|
976 | we do a 'hard' reset, giving you a new session and removing all | |
|
977 | references to objects from the current session. | |
|
978 | ||
|
976 | 979 | Examples |
|
977 | 980 | -------- |
|
978 | 981 | In [6]: a = 1 |
@@ -985,11 +988,11 b' Currently the magic system has the following functions:\\n"""' | |||
|
985 | 988 | |
|
986 | 989 | In [9]: %reset -f |
|
987 | 990 | |
|
988 |
In [1 |
|
|
989 |
Out[1 |
|
|
991 | In [1]: 'a' in _ip.user_ns | |
|
992 | Out[1]: False | |
|
990 | 993 | """ |
|
991 | ||
|
992 | if parameter_s == '-f': | |
|
994 | opts, args = self.parse_options(parameter_s,'sh') | |
|
995 | if 'f' in opts: | |
|
993 | 996 | ans = True |
|
994 | 997 | else: |
|
995 | 998 | ans = self.shell.ask_yes_no( |
@@ -997,13 +1000,16 b' Currently the magic system has the following functions:\\n"""' | |||
|
997 | 1000 | if not ans: |
|
998 | 1001 | print 'Nothing done.' |
|
999 | 1002 | return |
|
1000 | user_ns = self.shell.user_ns | |
|
1001 | for i in self.magic_who_ls(): | |
|
1002 | del(user_ns[i]) | |
|
1003 | ||
|
1004 | if 's' in opts: # Soft reset | |
|
1005 | user_ns = self.shell.user_ns | |
|
1006 | for i in self.magic_who_ls(): | |
|
1007 | del(user_ns[i]) | |
|
1003 | 1008 | |
|
1004 | # Also flush the private list of module references kept for script | |
|
1005 | # execution protection | |
|
1006 | self.shell.clear_main_mod_cache() | |
|
1009 | else: # Hard reset | |
|
1010 | self.shell.reset(new_session = True) | |
|
1011 | ||
|
1012 | ||
|
1007 | 1013 | |
|
1008 | 1014 | def magic_reset_selective(self, parameter_s=''): |
|
1009 | 1015 | """Resets the namespace by removing names defined by the user. |
@@ -379,6 +379,21 b' def test_xmode():' | |||
|
379 | 379 | for i in range(3): |
|
380 | 380 | _ip.magic("xmode") |
|
381 | 381 | nt.assert_equal(_ip.InteractiveTB.mode, xmode) |
|
382 | ||
|
383 | def test_reset_hard(): | |
|
384 | monitor = [] | |
|
385 | class A(object): | |
|
386 | def __del__(self): | |
|
387 | monitor.append(1) | |
|
388 | def __repr__(self): | |
|
389 | return "<A instance>" | |
|
390 | ||
|
391 | _ip.user_ns["a"] = A() | |
|
392 | _ip.run_cell("a") | |
|
393 | ||
|
394 | nt.assert_equal(monitor, []) | |
|
395 | _ip.magic_reset("-f") | |
|
396 | nt.assert_equal(monitor, [1]) | |
|
382 | 397 | |
|
383 | 398 | def doctest_who(): |
|
384 | 399 | """doctest for %who |
General Comments 0
You need to be logged in to leave comments.
Login now