##// END OF EJS Templates
Merge branch 'fix-del-method-exit-test' of http://github.com/takowl/ipython into takowl-fix-del-method-exit-test...
Thomas Kluyver -
r3178:5c6a3477 merge
parent child Browse files
Show More
@@ -819,8 +819,11 b' class InteractiveShell(Configurable, Magic):'
819
819
820 # Similarly, track all namespaces where references can be held and that
820 # Similarly, track all namespaces where references can be held and that
821 # we can safely clear (so it can NOT include builtin). This one can be
821 # we can safely clear (so it can NOT include builtin). This one can be
822 # a simple list.
822 # a simple list. Note that the main execution namespaces, user_ns and
823 self.ns_refs_table = [ user_ns, user_global_ns, self.user_ns_hidden,
823 # user_global_ns, can NOT be listed here, as clearing them blindly
824 # causes errors in object __del__ methods. Instead, the reset() method
825 # clears them manually and carefully.
826 self.ns_refs_table = [ self.user_ns_hidden,
824 self.internal_ns, self._main_ns_cache ]
827 self.internal_ns, self._main_ns_cache ]
825
828
826 def make_user_namespaces(self, user_ns=None, user_global_ns=None):
829 def make_user_namespaces(self, user_ns=None, user_global_ns=None):
@@ -985,6 +988,18 b' class InteractiveShell(Configurable, Magic):'
985 # Restore the user namespaces to minimal usability
988 # Restore the user namespaces to minimal usability
986 for ns in self.ns_refs_table:
989 for ns in self.ns_refs_table:
987 ns.clear()
990 ns.clear()
991
992 # The main execution namespaces must be cleared very carefully,
993 # skipping the deletion of the builtin-related keys, because doing so
994 # would cause errors in many object's __del__ methods.
995 for ns in [self.user_ns, self.user_global_ns]:
996 drop_keys = set(ns.keys())
997 drop_keys.discard('__builtin__')
998 drop_keys.discard('__builtins__')
999 for k in drop_keys:
1000 del ns[k]
1001
1002 # Restore the user namespaces to minimal usability
988 self.init_user_ns()
1003 self.init_user_ns()
989
1004
990 # Restore the default and user aliases
1005 # Restore the default and user aliases
@@ -88,12 +88,13 b' def doctest_reset_del():'
88
88
89 In [2]: class A(object):
89 In [2]: class A(object):
90 ...: def __del__(self):
90 ...: def __del__(self):
91 ...: str("Hi")
91 ...: print str("Hi")
92 ...:
92 ...:
93
93
94 In [3]: a = A()
94 In [3]: a = A()
95
95
96 In [4]: get_ipython().reset()
96 In [4]: get_ipython().reset()
97 Hi
97
98
98 In [5]: 1+1
99 In [5]: 1+1
99 Out[5]: 2
100 Out[5]: 2
General Comments 0
You need to be logged in to leave comments. Login now