These are chat archives for ipython/ipython

15th
Jun 2018
Thomas Robitaille
@astrofrog
Jun 15 2018 08:54
Hi all - I'm running into an issue that is caused by the fact that IPython appears to keep a reference to any object that has been output in the past history - accessing ipython.user_ns shows keys like _7, _10, and so on for which the corresponding values are values that were output in the past. Is there any way to prevent the previous outputs from being stored like this without running %reset?
Basically the issue is that I'm using IPython inside a Qt application and if I access any of the widgets programmatically then this causes issues because they will never be garbage collected properly if I close them at any point via Qt (since there is a remaining reference in the IPython user_ns)
Min RK
@minrk
Jun 15 2018 09:06
You can truncate the output cache with InteractiveShell.cache_size = <int>. That ought to expire cached outputs older than a bit
Thomas Robitaille
@astrofrog
Jun 15 2018 09:07
@minrk - thanks! Is it possible to set it to 0 to never cache the output?
Min RK
@minrk
Jun 15 2018 09:09
Yes, I believe so
Thomas Robitaille
@astrofrog
Jun 15 2018 09:18
Does cache_size need to be set before InteractiveShell is instantiated for it to matter?
Min RK
@minrk
Jun 15 2018 09:18
I think so
Thomas Robitaille
@astrofrog
Jun 15 2018 09:30

In my case I'm starting things using a QtInProcessKernelManager - I managed to get it to work by doing:

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.cache_size.default_value = 0

before instantiating QtInProcessKernelManager, but not sure if that's the cleanest way?

Min RK
@minrk
Jun 15 2018 10:01
If you want to hardcode it, you can set InteractiveShell.cache_size = 0
Thomas Robitaille
@astrofrog
Jun 15 2018 10:19
Ok, thanks!