##// END OF EJS Templates
Implement hard reset with '%reset -h' call....
Thomas Kluyver -
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
@@ -1044,6 +1044,9 b' class InteractiveShell(Configurable, Magic):'
1044 1044 """
1045 1045 # Clear histories
1046 1046 self.history_manager.reset(new_session)
1047
1048 # Flush cached output items
1049 self.displayhook.flush()
1047 1050
1048 1051 # Reset counter used to index all histories
1049 1052 self.execution_count = 0
@@ -1068,6 +1071,10 b' class InteractiveShell(Configurable, Magic):'
1068 1071 # Restore the default and user aliases
1069 1072 self.alias_manager.clear_aliases()
1070 1073 self.alias_manager.init_aliases()
1074
1075 # Flush the private list of module references kept for script
1076 # execution protection
1077 self.clear_main_mod_cache()
1071 1078
1072 1079 def reset_selective(self, regex=None):
1073 1080 """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 -h : 'Hard' reset: gives you a new session and removes all
975 references to objects from the current session. By default, we
976 do a 'soft' reset, which only clears out your namespace, and
977 leaves input and output history around.
978
976 979 Examples
977 980 --------
978 981 In [6]: a = 1
@@ -988,8 +991,8 b' Currently the magic system has the following functions:\\n"""'
988 991 In [10]: 'a' in _ip.user_ns
989 992 Out[10]: False
990 993 """
991
992 if parameter_s == '-f':
994 opts, args = self.parse_options(parameter_s,'fh')
995 if 'f' in opts:
993 996 ans = True
994 997 else:
995 998 ans = self.shell.ask_yes_no(
@@ -997,13 +1000,14 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 1003
1004 # Also flush the private list of module references kept for script
1005 # execution protection
1006 self.shell.clear_main_mod_cache()
1004 if 'h' in opts: # Hard reset
1005 self.shell.reset(new_session = True)
1006
1007 else: # Soft reset
1008 user_ns = self.shell.user_ns
1009 for i in self.magic_who_ls():
1010 del(user_ns[i])
1007 1011
1008 1012 def magic_reset_selective(self, parameter_s=''):
1009 1013 """Resets the namespace by removing names defined by the user.
General Comments 0
You need to be logged in to leave comments. Login now