[IPython-dev] Should IPython be a singleton?
robert.kern at gmail.com
Wed Aug 26 19:27:00 EDT 2009
On 2009-08-26 18:17 PM, Brian Granger wrote:
> When tracking down problems like this, one thing you have to be very
> about is not creating references via your instrumentation. It's
> easy to do. :-)
> Yes, it is very tough to do right.
> __builtins__.__IPYTHON__ and __builtins__.__IPYTHON__active are two
> and the remaining one is a cell object. I'm not sure where he is
> coming from.
> In my version, I have gotten rid of __IPYTHON__ and IPYTHON_active is an
> What is a cell object?
It is created when there are closures.
> Could I see the foo.py script?
Oops! Sorry. I thought I catted it. Here it is with a few more things cleaned up.
[~]$ cat foo.py
from IPython.core.shell import InteractiveShell
real_main = sys.modules['__main__']
s = InteractiveShell('foo')
# Clean up.
if hasattr(sys, 'ipcompleter'):
sys.stdin = sys.__stdin__
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
sys.displayhook = sys.__displayhook__
sys.excepthook = sys.__excepthook__
sys.modules['__main__'] = real_main
for obj in gc.get_objects():
if getattr(type(obj), '__name__', None) == 'InteractiveShell':
refs = gc.get_referrers(obj)
print '%s references:' % len(refs)
for ref in refs:
if isinstance(ref, dict):
print 'A dict with keys: %r' % (ref.keys(),)
elif isinstance(ref, list):
print 'A list of %s elements; probably gc.get_objects().' %
elif type(ref).__name__ == 'cell':
print 'A cell: %r' % ref
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the IPython-dev