From db762d9fd077b080233c32b4f488a5013a96dd77 2012-03-16 23:33:04 From: Min RK Date: 2012-03-16 23:33:04 Subject: [PATCH] Merge pull request #1496 from rkern/fix-finalize-displayhook BUG: LBYL when clearing the output history on shutdown. closes #1241 closes #676 --- 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.___ = '', '', ''