From c8437ab52085d5be86e5d4e2aab304631b3925cc 2012-04-06 21:34:58 From: Robert Kern Date: 2012-04-06 21:34:58 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.___ = '', '', ''