Skip to content

Commit

Permalink
Objects can still be pickled after a %reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Apr 14, 2011
1 parent 89f3d69 commit 5411be8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions IPython/core/interactiveshell.py
Expand Up @@ -1059,24 +1059,25 @@ def reset(self, new_session=True):
# Restore the user namespaces to minimal usability
for ns in self.ns_refs_table:
ns.clear()

# In some situations, e.g. testing, our fake main module has a __dict__
# separate from the user_ns: if so, we need to clear it manually.
if self.user_ns is not self.user_ns_mod.__dict__:
self.user_ns_mod.__dict__.clear()

# The main execution namespaces must be cleared very carefully,
# skipping the deletion of the builtin-related keys, because doing so
# would cause errors in many object's __del__ methods.
for ns in [self.user_ns, self.user_global_ns]:
drop_keys = set(ns.keys())
drop_keys.discard('__name__')
drop_keys.discard('__builtin__')
drop_keys.discard('__builtins__')
for k in drop_keys:
del ns[k]

# Restore the user namespaces to minimal usability
self.init_user_ns()

# In some situations, e.g. testing, our fake main module has a __dict__
# separate from the user_ns: if so, we need to clear it manually.
if self.user_ns is not self.user_ns_mod.__dict__:
init_fakemod_dict(self.user_ns_mod, self.user_ns)

# Restore the default and user aliases
self.alias_manager.clear_aliases()
Expand Down

0 comments on commit 5411be8

Please sign in to comment.