diff --git a/IPython/core/builtin_trap.py b/IPython/core/builtin_trap.py index 0cdefd6..ad0eb2d 100644 --- a/IPython/core/builtin_trap.py +++ b/IPython/core/builtin_trap.py @@ -102,11 +102,6 @@ class BuiltinTrap(Configurable): for name, func in self.auto_builtins.iteritems(): add_builtin(name, func) - # Keep in the builtins a flag for when IPython is active. We set it - # with setdefault so that multiple nested IPythons don't clobber one - # another. - __builtin__.__dict__.setdefault('__IPYTHON__active', 0) - def deactivate(self): """Remove any builtins which might have been added by add_builtins, or restore overwritten ones to their previous values.""" @@ -115,7 +110,3 @@ class BuiltinTrap(Configurable): remove_builtin(key, val) self._orig_builtins.clear() self._builtins_added = False - try: - del __builtin__.__dict__['__IPYTHON__active'] - except KeyError: - pass diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index e88c44a..d430e3b 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -573,6 +573,20 @@ class InteractiveShell(SingletonConfigurable, Magic): self.magic_logstart() def init_builtins(self): + # A single, static flag that we set to True. Its presence indicates + # that an IPython shell has been created, and we make no attempts at + # removing on exit or representing the existence of more than one + # IPython at a time. + builtin_mod.__dict__['__IPYTHON__'] = True + + # In 0.11 we introduced '__IPYTHON__active' as an integer we'd try to + # manage on enter/exit, but with all our shells it's virtually + # impossible to get all the cases right. We're leaving the name in for + # those who adapted their codes to check for this flag, but will + # eventually remove it after a few more releases. + builtin_mod.__dict__['__IPYTHON__active'] = \ + 'Deprecated, check for __IPYTHON__' + self.builtin_trap = BuiltinTrap(shell=self) def init_inspector(self): diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index f8cc10d..c438750 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -341,9 +341,6 @@ class TerminalInteractiveShell(InteractiveShell): more = False - # Mark activity in the builtins - __builtin__.__dict__['__IPYTHON__active'] += 1 - if self.has_readline: self.readline_startup_hook(self.pre_readline) hlen_b4_cell = self.readline.get_current_history_length() @@ -413,9 +410,6 @@ class TerminalInteractiveShell(InteractiveShell): hlen_b4_cell = \ self._replace_rlhist_multiline(source_raw, hlen_b4_cell) - # We are off again... - __builtin__.__dict__['__IPYTHON__active'] -= 1 - # Turn off the exit flag, so the mainloop can be restarted if desired self.exit_now = False