From 146be2379ebe8d02faea85466a2671149cf58a48 2009-10-17 19:27:00 From: Brian Granger Date: 2009-10-17 19:27:00 Subject: [PATCH] ipapi.get now returns None if there are no InteractiveShells running. It used to simply raise an IndexError, which was bad. --- diff --git a/IPython/core/ipapi.py b/IPython/core/ipapi.py index dc1f1f5..8ee88a2 100644 --- a/IPython/core/ipapi.py +++ b/IPython/core/ipapi.py @@ -18,16 +18,19 @@ has been made into a component, this module will be sent to deathrow. # Imports #----------------------------------------------------------------------------- -from IPython.core.error import TryNext, UsageError +from IPython.core.error import TryNext, UsageError, IPythonCoreError #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- + def get(): """Get the most recently created InteractiveShell instance.""" from IPython.core.iplib import InteractiveShell insts = InteractiveShell.get_instances() + if len(insts)==0: + return None most_recent = insts[0] for inst in insts[1:]: if inst.created > most_recent.created: