[IPython-dev] Should IPython be a singleton?

Robert Kern robert.kern at gmail.com
Wed Aug 26 17:55:09 EDT 2009

On 2009-08-26 16:36 PM, Brian Granger wrote:
> Currently, IPython is not a singleton, but effectively it is.  We do a
> number of things that essentially prevent
> multiple InteractiveShells from being created:
> 1.  We muck with sys.excepthook, sys.displayhook, sys.ipcompleter,
> sys.stdin, sys.stdout

That doesn't have to be a problem. That's why I wrote all of those *Trap 
classes. And as far as I can tell, sys.ipcompleter is entirely from IPython, not 
Python itself. I have no idea why it's in the sys namespace in the first place.

> 2.  We push a number of thing into __builtin__ that point to the
> specific InteractiveShell:
> exit
> quit
> reload

Could be Trapped, as well.

> 3.  Because of severe cycles in our object graph, an InterativeShell
> instances can't be
> garbage collected.

Or rather, they *are* garbage collected and not __del__eted.

> So, should we actually make InteractiveShell a singleton?  There are a
> couple of different
> options:
> 1.  One InteractiveShell per process - a true singleton.
> 2.  One InteractiveShell at a time, but multiple (serial) ones in a process.
> 3.  Multiple, sumultanous InteractiveShells
> The only subtlety is that some level of nesting is possible.
> Just a note: it will take a lot of refactoring to really implement any
> of the above options.
> But, I want to know what we are aiming for as this issue affects many
> design choices.

#3 would be really, really desirable, and I think it is feasible.

Robert Kern

"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 mailing list