override exit handling for IPython TerminalInteractiveShell (PY-5172)
authorAlexander Marchuk <Alexander.Marchuk@jetbrains.com>
Mon, 24 Mar 2014 12:23:37 +0000 (13:23 +0100)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Thu, 3 Apr 2014 15:39:29 +0000 (17:39 +0200)
(cherry picked from commit 05c1755)

python/helpers/pydev/pydev_ipython_console_011.py

index a6c0d8207a0411a5e1999ab204b860c2fd206298..15c5b85c19e0f4e8cf0b156971676718490a4807 100644 (file)
@@ -33,10 +33,15 @@ class PyDevFrontEnd:
         # Store certain global objects that IPython modifies
         _displayhook = sys.displayhook
         _excepthook = sys.excepthook
-    
+
+        class ClosablePyDevTerminalInteractiveShell(TerminalInteractiveShell):
+            '''Override ask_exit() method for correct exit, exit(), etc. handling.'''
+            def ask_exit(self):
+                sys.exit()
+
         # Create and initialize our IPython instance.
-        shell = TerminalInteractiveShell.instance()
-    
+        shell = ClosablePyDevTerminalInteractiveShell.instance()
+
         shell.showtraceback = _showtraceback
         # IPython is ready, now clean up some global state...
         
@@ -55,12 +60,12 @@ class PyDevFrontEnd:
             import builtins as __builtin__
         __builtin__._ip = shell
         __builtin__.get_ipython = get_ipython
-        
+
         # We want to print to stdout/err as usual.
         io.stdout = original_stdout
         io.stderr = original_stderr
-    
-        
+
+
         self._curr_exec_lines = []
         self.ipython = shell