##// END OF EJS Templates
Merge branch 'hard-reset' of https://github.com/takluyver/ipython into takluyver-hard-reset
Thomas Kluyver -
r3536:c45fd858 merge
parent child Browse files
Show More
@@ -319,6 +319,9 b' class DisplayHook(Configurable):'
319 except: pass
319 except: pass
320 self.shell.user_ns['_oh'].clear()
320 self.shell.user_ns['_oh'].clear()
321
321
322 # Release our own references to objects:
323 self._, self.__, self.___ = '', '', ''
324
322 if '_' not in __builtin__.__dict__:
325 if '_' not in __builtin__.__dict__:
323 self.shell.user_ns.update({'_':None,'__':None, '___':None})
326 self.shell.user_ns.update({'_':None,'__':None, '___':None})
324 import gc
327 import gc
@@ -1045,6 +1045,9 b' class InteractiveShell(Configurable, Magic):'
1045 """
1045 """
1046 # Clear histories
1046 # Clear histories
1047 self.history_manager.reset(new_session)
1047 self.history_manager.reset(new_session)
1048
1049 # Flush cached output items
1050 self.displayhook.flush()
1048
1051
1049 # Reset counter used to index all histories
1052 # Reset counter used to index all histories
1050 self.execution_count = 0
1053 self.execution_count = 0
@@ -1069,6 +1072,10 b' class InteractiveShell(Configurable, Magic):'
1069 # Restore the default and user aliases
1072 # Restore the default and user aliases
1070 self.alias_manager.clear_aliases()
1073 self.alias_manager.clear_aliases()
1071 self.alias_manager.init_aliases()
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 def reset_selective(self, regex=None):
1080 def reset_selective(self, regex=None):
1074 """Clear selective variables from internal namespaces based on a
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 def magic_reset(self, parameter_s=''):
967 def magic_reset(self, parameter_s=''):
968 """Resets the namespace by removing all names defined by the user.
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 Parameters
970 Parameters
973 ----------
971 ----------
974 -f : force reset without asking for confirmation.
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 Examples
979 Examples
977 --------
980 --------
978 In [6]: a = 1
981 In [6]: a = 1
@@ -985,11 +988,11 b' Currently the magic system has the following functions:\\n"""'
985
988
986 In [9]: %reset -f
989 In [9]: %reset -f
987
990
988 In [10]: 'a' in _ip.user_ns
991 In [1]: 'a' in _ip.user_ns
989 Out[10]: False
992 Out[1]: False
990 """
993 """
991
994 opts, args = self.parse_options(parameter_s,'sh')
992 if parameter_s == '-f':
995 if 'f' in opts:
993 ans = True
996 ans = True
994 else:
997 else:
995 ans = self.shell.ask_yes_no(
998 ans = self.shell.ask_yes_no(
@@ -997,13 +1000,16 b' Currently the magic system has the following functions:\\n"""'
997 if not ans:
1000 if not ans:
998 print 'Nothing done.'
1001 print 'Nothing done.'
999 return
1002 return
1000 user_ns = self.shell.user_ns
1003
1001 for i in self.magic_who_ls():
1004 if 's' in opts: # Soft reset
1002 del(user_ns[i])
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
1009 else: # Hard reset
1005 # execution protection
1010 self.shell.reset(new_session = True)
1006 self.shell.clear_main_mod_cache()
1011
1012
1007
1013
1008 def magic_reset_selective(self, parameter_s=''):
1014 def magic_reset_selective(self, parameter_s=''):
1009 """Resets the namespace by removing names defined by the user.
1015 """Resets the namespace by removing names defined by the user.
@@ -379,6 +379,21 b' def test_xmode():'
379 for i in range(3):
379 for i in range(3):
380 _ip.magic("xmode")
380 _ip.magic("xmode")
381 nt.assert_equal(_ip.InteractiveTB.mode, xmode)
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 def doctest_who():
398 def doctest_who():
384 """doctest for %who
399 """doctest for %who
General Comments 0
You need to be logged in to leave comments. Login now