diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py index a8a8a92..7f0817f 100644 --- a/IPython/core/displayhook.py +++ b/IPython/core/displayhook.py @@ -319,6 +319,9 @@ class DisplayHook(Configurable): except: pass self.shell.user_ns['_oh'].clear() + # Release our own references to objects: + self._, self.__, self.___ = '', '', '' + if '_' not in __builtin__.__dict__: self.shell.user_ns.update({'_':None,'__':None, '___':None}) import gc diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index d3c2c41..20f9dbc 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1044,6 +1044,9 @@ class InteractiveShell(Configurable, Magic): """ # Clear histories self.history_manager.reset(new_session) + + # Flush cached output items + self.displayhook.flush() # Reset counter used to index all histories self.execution_count = 0 @@ -1068,6 +1071,10 @@ class InteractiveShell(Configurable, Magic): # Restore the default and user aliases self.alias_manager.clear_aliases() self.alias_manager.init_aliases() + + # Flush the private list of module references kept for script + # execution protection + self.clear_main_mod_cache() def reset_selective(self, regex=None): """Clear selective variables from internal namespaces based on a diff --git a/IPython/core/magic.py b/IPython/core/magic.py index f6c2c65..d008c93 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -967,12 +967,15 @@ Currently the magic system has the following functions:\n""" def magic_reset(self, parameter_s=''): """Resets the namespace by removing all names defined by the user. - Input/Output history are left around in case you need them. - Parameters ---------- -f : force reset without asking for confirmation. - + + -h : 'Hard' reset: gives you a new session and removes all + references to objects from the current session. By default, we + do a 'soft' reset, which only clears out your namespace, and + leaves input and output history around. + Examples -------- In [6]: a = 1 @@ -988,8 +991,8 @@ Currently the magic system has the following functions:\n""" In [10]: 'a' in _ip.user_ns Out[10]: False """ - - if parameter_s == '-f': + opts, args = self.parse_options(parameter_s,'fh') + if 'f' in opts: ans = True else: ans = self.shell.ask_yes_no( @@ -997,13 +1000,14 @@ Currently the magic system has the following functions:\n""" if not ans: print 'Nothing done.' return - user_ns = self.shell.user_ns - for i in self.magic_who_ls(): - del(user_ns[i]) - # Also flush the private list of module references kept for script - # execution protection - self.shell.clear_main_mod_cache() + if 'h' in opts: # Hard reset + self.shell.reset(new_session = True) + + else: # Soft reset + user_ns = self.shell.user_ns + for i in self.magic_who_ls(): + del(user_ns[i]) def magic_reset_selective(self, parameter_s=''): """Resets the namespace by removing names defined by the user.