Thanks! I will have a look at this to see how it differs from what I have been doing.<br><br>Brian<br><br><div class="gmail_quote">On Wed, Aug 26, 2009 at 4:27 PM, Robert Kern <span dir="ltr"><<a href="mailto:robert.kern@gmail.com">robert.kern@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On 2009-08-26 18:17 PM, Brian Granger wrote:<br>
><br>
>     When tracking down problems like this, one thing you have to be very<br>
>     careful<br>
>     about is not creating references via your instrumentation. It's<br>
>     disturbingly<br>
>     easy to do. :-)<br>
><br>
><br>
> Yes, it is very tough to do right.<br>
><br>
>     __builtins__.__IPYTHON__ and __builtins__.__IPYTHON__active are two<br>
>     culprits,<br>
>     and the remaining one is a cell object. I'm not sure where he is<br>
>     coming from.<br>
><br>
><br>
> In my version, I have gotten rid of __IPYTHON__ and IPYTHON_active is an<br>
> int.<br>
><br>
> What is a cell object?<br>
<br>
</div>It is created when there are closures.<br>
<br>
<a href="http://docs.python.org/c-api/cell.html" target="_blank">http://docs.python.org/c-api/cell.html</a><br>
<div class="im"><br>
> Could I see the foo.py script?<br>
<br>
</div>Oops! Sorry. I thought I catted it. Here it is with a few more things cleaned up.<br>
<br>
[~]$ cat foo.py<br>
import gc<br>
import sys<br>
import types<br>
<br>
from IPython.core.shell import InteractiveShell<br>
<br>
real_main = sys.modules['__main__']<br>
<br>
s = InteractiveShell('foo')<br>
print s<br>
<br>
# Clean up.<br>
del s.shell<br>
del s<br>
del __builtins__.__IPYTHON__active<br>
del __builtins__.__IPYTHON__<br>
if hasattr(sys, 'ipcompleter'):<br>
     del sys.ipcompleter<br>
sys.stdin = sys.__stdin__<br>
sys.stdout = sys.__stdout__<br>
sys.stderr = sys.__stderr__<br>
sys.displayhook = sys.__displayhook__<br>
sys.excepthook = sys.__excepthook__<br>
sys.modules['__main__'] = real_main<br>
<br>
for obj in gc.get_objects():<br>
     if getattr(type(obj), '__name__', None) == 'InteractiveShell':<br>
         print obj<br>
         refs = gc.get_referrers(obj)<br>
         print '%s references:' % len(refs)<br>
         for ref in refs:<br>
             print type(ref)<br>
             if isinstance(ref, dict):<br>
                 print 'A dict with keys: %r' % (ref.keys(),)<br>
             elif isinstance(ref, list):<br>
                 print 'A list of %s elements; probably gc.get_objects().' %<br>
len(ref)<br>
             elif type(ref).__name__ == 'cell':<br>
                 print 'A cell: %r' % ref<br>
                 print ref.cell_contents<br>
             else:<br>
                 print ref<br>
             print<br>
<font color="#888888"><br>
<br>
--<br>
</font><div><div></div><div class="h5">Robert Kern<br>
<br>
"I have come to believe that the whole world is an enigma, a harmless enigma<br>
  that is made terrible by our own mad attempt to interpret it as though it had<br>
  an underlying truth."<br>
   -- Umberto Eco<br>
<br>
_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
</div></div></blockquote></div><br>