Repository: ipython/ipython

Issue:
interactive -i mode doesn't work after exceptions since 4.1.1
Hi,

I recently noticed that after upgrading from 4.0.3 to 4.1.1 (from anaconda), `-i` flag no longer drops to the interactive shell but quits after an exception. I downgraded to 4.0.3 and it is now working correctly. I searched on google but couldn't find a similar issue. Any ideas?



Discussion:
I couldn't immediately reproduce this either on master or with the 4.1.1 tag. What exception do you see?

I think I couldn't explain it clearly. I'll try now with code output :)

```
(root)caglayan@n1:~$ ipython -i test.py
Python 2.7.11 |Continuum Analytics, Inc.| (default, Dec  6 2015, 18:08:32) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.3 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/lium/buster1/caglayan/test.py in <module>()
      1 
      2 x = [10, 20]
----> 3 y = x.index(100)

ValueError: 100 is not in list

In [1]: !cat test.py

x = [10, 20]
y = x.index(100)

In [2]: (I'm still in Ipython and I can debug the exception)
```

Now with 4.1.1:

```
$ conda update ipython
....

(root)caglayan@n1:~$ ipython -i test.py                                                                                                                                                                                                        
Python 2.7.11 |Continuum Analytics, Inc.| (default, Dec  6 2015, 18:08:32) 
Type "copyright", "credits" or "license" for more information.

IPython 4.1.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/lium/buster1/caglayan/test.py in <module>()
      1 
      2 x = [10, 20]
----> 3 y = x.index(100)

ValueError: 100 is not in list
(root)caglayan@n1:~$ (Dropped to bash)
```


Resolving patch:
diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py
--- a/IPython/core/shellapp.py
+++ b/IPython/core/shellapp.py
@@ -198,6 +198,8 @@ class InteractiveShellApp(Configurable):
     )
     shell = Instance('IPython.core.interactiveshell.InteractiveShellABC',
                      allow_none=True)
+    # whether interact-loop should start
+    interact = Bool(True)
     
     user_ns = Instance(dict, args=None, allow_none=True)
     def _user_ns_changed(self, name, old, new):
@@ -411,6 +413,8 @@ def _run_cmd_line_code(self):
                 self.log.warning("Error in executing line in user namespace: %s" %
                               line)
                 self.shell.showtraceback()
+                if not self.interact:
+                    self.exit(1)
 
         # Like Python itself, ignore the second if the first of these is present
         elif self.file_to_run:
@@ -419,7 +423,8 @@ def _run_cmd_line_code(self):
                 self._exec_file(fname, shell_futures=True)
             except:
                 self.shell.showtraceback(tb_offset=4)
-                self.exit(1)
+                if not self.interact:
+                    self.exit(1)
 
     def _run_module(self):
         """Run module specified at the command-line."""
diff --git a/IPython/terminal/ipapp.py b/IPython/terminal/ipapp.py
--- a/IPython/terminal/ipapp.py
+++ b/IPython/terminal/ipapp.py
@@ -272,7 +272,6 @@ def _file_to_run_changed(self, name, old, new):
     _module_to_run_changed = _file_to_run_changed
 
     # internal, not-configurable
-    interact=Bool(True)
     something_to_run=Bool(False)
 
     def parse_command_line(self, argv=None):


Test patch: