From c28834f3d7a0da16750f042fc50eca88ef2007be 2011-04-14 23:07:11 From: Thomas Kluyver Date: 2011-04-14 23:07:11 Subject: [PATCH] Shell's reset method clears namespace from last %run command. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 71cb7db..6de3956 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1038,10 +1038,8 @@ class InteractiveShell(Configurable, Magic): self.user_ns.update(ns) def reset(self, new_session=True): - """Clear all internal namespaces. - - Note that this is much more aggressive than %reset, since it clears - fully all namespaces, as well as all input/output lists. + """Clear all internal namespaces, and attempt to release references to + user objects. If new_session is True, a new history session will be opened. """ @@ -1078,6 +1076,9 @@ class InteractiveShell(Configurable, Magic): # Flush the private list of module references kept for script # execution protection self.clear_main_mod_cache() + + # Clear out the namespace from the last %run + self.new_main_mod() def reset_selective(self, regex=None): """Clear selective variables from internal namespaces based on a diff --git a/IPython/core/tests/tclass.py b/IPython/core/tests/tclass.py index c9ec7fc..38b3a5a 100644 --- a/IPython/core/tests/tclass.py +++ b/IPython/core/tests/tclass.py @@ -10,10 +10,11 @@ import sys class C(object): def __init__(self,name): self.name = name + self.flush_stdout = sys.stdout.flush def __del__(self): print 'tclass.py: deleting object:',self.name - sys.stdout.flush() + self.flush_stdout() try: name = sys.argv[1] diff --git a/IPython/core/tests/test_run.py b/IPython/core/tests/test_run.py index 159a2f1..14b0fe4 100644 --- a/IPython/core/tests/test_run.py +++ b/IPython/core/tests/test_run.py @@ -202,5 +202,6 @@ class TestMagicRunSimple(tt.TempFileMixin): ARGV 1-: [u'C-first'] ARGV 1-: [u'C-second'] tclass.py: deleting object: C-first +tclass.py: deleting object: C-second """ tt.ipexec_validate(self.fname, out)