From f6d2e7a6b66d1da1b5ca75dd87beeec5e5595ecd 2012-03-15 15:34:51 From: Robert Kern Date: 2012-03-15 15:34:51 Subject: [PATCH] BUG: LBYL when clearing the output history on shutdown. --- diff --git a/IPython/core/displayhook.py b/IPython/core/displayhook.py index e2e9c0d..5eebb5f 100644 --- a/IPython/core/displayhook.py +++ b/IPython/core/displayhook.py @@ -252,7 +252,11 @@ class DisplayHook(Configurable): try: del self.shell.user_ns[key] except: pass - self.shell.user_ns['_oh'].clear() + # In some embedded circumstances, the user_ns doesn't have the + # '_oh' key set up. + oh = self.shell.user_ns.get('_oh', None) + if oh is not None: + oh.clear() # Release our own references to objects: self._, self.__, self.___ = '', '', ''