Show More
@@ -819,8 +819,11 b' class InteractiveShell(Configurable, Magic):' | |||
|
819 | 819 | |
|
820 | 820 | # Similarly, track all namespaces where references can be held and that |
|
821 | 821 | # we can safely clear (so it can NOT include builtin). This one can be |
|
822 | # a simple list. | |
|
823 | self.ns_refs_table = [ user_ns, user_global_ns, self.user_ns_hidden, | |
|
822 | # a simple list. Note that the main execution namespaces, user_ns and | |
|
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 | 827 | self.internal_ns, self._main_ns_cache ] |
|
825 | 828 | |
|
826 | 829 | def make_user_namespaces(self, user_ns=None, user_global_ns=None): |
@@ -985,6 +988,18 b' class InteractiveShell(Configurable, Magic):' | |||
|
985 | 988 | # Restore the user namespaces to minimal usability |
|
986 | 989 | for ns in self.ns_refs_table: |
|
987 | 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 | 1003 | self.init_user_ns() |
|
989 | 1004 | |
|
990 | 1005 | # Restore the default and user aliases |
General Comments 0
You need to be logged in to leave comments.
Login now