[IPython-dev] Getting InteractiveShell to clean up after itself
Wed Aug 26 13:19:04 CDT 2009
Currently in my ipython-app branch, InteractiveShell is a real object that
can be instantiated:
ip = InteractiveShell()
But, when you do:
The InteractiveShell.__del__ does *not* get called. This is not too
surprising given how garbage collection
works in python:
* We have cycles to InteractiveShell all over the place (everybody points
* In Python cycles + __del__ methods => some objects can't be collected
even when gc.collect() is run.
I would like to resolve this problem and I see two ways of accomplishing it:
1. Begin to use weakrefs everywhere. This would break all our cycles and
would probably be a good idea
anyways. If we do this with discipline, we might be able to get a __del__
method called to do cleanup
(removing sys.*hook, removing things injected into __builtin__, etc.).
2. Add a .cleanup() method that does all the cleanup by hand. This won't
break cycles, but it would ensure
that the InteractiveShell had "detached" from everything outside of itself.
If we go this way, and drop 2.4
support, we could make InteractiveShell a context manager and have cleanup
called when the context
My goal is that we could create and destroy InteractiveShell instances (for
testing, etc.) whenever we want
or need and they would always clean up after themselves.
If we don't go this route, then I think we should make InteractiveShell a
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev