##// END OF EJS Templates
Fix bug with reset() that was causing errors in __del__ methods....
Fernando Perez -
Show More
@@ -810,8 +810,11 b' class InteractiveShell(Configurable, Magic):'
810
810
811 # Similarly, track all namespaces where references can be held and that
811 # Similarly, track all namespaces where references can be held and that
812 # we can safely clear (so it can NOT include builtin). This one can be
812 # we can safely clear (so it can NOT include builtin). This one can be
813 # a simple list.
813 # a simple list. Note that the main execution namespaces, user_ns and
814 self.ns_refs_table = [ user_ns, user_global_ns, self.user_ns_hidden,
814 # user_global_ns, can NOT be listed here, as clearing them blindly
815 # causes errors in object __del__ methods. Instead, the reset() method
816 # clears them manually and carefully.
817 self.ns_refs_table = [ self.user_ns_hidden,
815 self.internal_ns, self._main_ns_cache ]
818 self.internal_ns, self._main_ns_cache ]
816
819
817 def make_user_namespaces(self, user_ns=None, user_global_ns=None):
820 def make_user_namespaces(self, user_ns=None, user_global_ns=None):
@@ -968,9 +971,6 b' class InteractiveShell(Configurable, Magic):'
968 Note that this is much more aggressive than %reset, since it clears
971 Note that this is much more aggressive than %reset, since it clears
969 fully all namespaces, as well as all input/output lists.
972 fully all namespaces, as well as all input/output lists.
970 """
973 """
971 for ns in self.ns_refs_table:
972 ns.clear()
973
974 self.alias_manager.clear_aliases()
974 self.alias_manager.clear_aliases()
975
975
976 # Clear input and output histories
976 # Clear input and output histories
@@ -978,9 +978,22 b' class InteractiveShell(Configurable, Magic):'
978 self.input_hist_raw[:] = []
978 self.input_hist_raw[:] = []
979 self.output_hist.clear()
979 self.output_hist.clear()
980
980
981 # Clear namespaces holding user references
982 for ns in self.ns_refs_table:
983 ns.clear()
984
985 # The main execution namespaces must be cleared very carefully,
986 # skipping the deletion of the __builtin__ key, because doing so would
987 # cause errors in many object's __del__ methods.
988 for ns in [self.user_ns, self.user_global_ns]:
989 drop_keys = set(ns.keys())
990 drop_keys.discard('__builtin__')
991 for k in drop_keys:
992 del ns[k]
993
981 # Restore the user namespaces to minimal usability
994 # Restore the user namespaces to minimal usability
982 self.init_user_ns()
995 self.init_user_ns()
983
996
984 # Restore the default and user aliases
997 # Restore the default and user aliases
985 self.alias_manager.init_aliases()
998 self.alias_manager.init_aliases()
986
999
General Comments 0
You need to be logged in to leave comments. Login now