title: simple IPython example raises exception on sys.exit()
body: <p>I'm doing some very simple PySide (and PyQt) tutorials in IPython. One tutorial just creates a window with some sliders to demonstrate slots and signals.</p>
  
  <p>When I close the window of the running demo application, I see this error:</p>
  
  <pre><code>An exception has occurred, use %tb to see the full traceback.
  SystemExit: 0
  To exit: use 'exit', 'quit', or Ctrl-D.
  </code></pre>
  
  <p>So I run %tb and get this:</p>
  
  <pre><code>SystemExit                                Traceback (most recent call last)
  /Workspaces/scratch/&lt;ipython-input-1-88966dcfb499&gt; in &lt;module&gt;()
       33 
       34 if __name__ == "__main__":
  ---&gt; 35     main()
  
  /Workspaces/scratch/&lt;ipython-input-1-88966dcfb499&gt; in main()
       29         w.show()
       30         app.exec_()
  ---&gt; 31         sys.exit(0)
       32 
       33 
  
  SystemExit: 0
  </code></pre>
  
  <p>If I try to execute my code again, I get this:</p>
  
  <pre><code>RuntimeError: A QApplication instance already exists.
  </code></pre>
  
  <p>In case it helps, here my code:</p>
  
  <pre><code>from PySide.QtCore import *
  from PySide.QtGui import *
  import sys
  
  class MyWindow(QWidget):
      def __init__(self):
          QWidget.__init__(self, None)
  
          vbox = QVBoxLayout(self)
  
          self.slider1 = QSlider(Qt.Horizontal)
          self.slider1.setRange(0, 99)
          self.slider1.setValue(0)
          vbox.addWidget(self.slider1)
  
          self.slider2 = QSlider(Qt.Horizontal)
          self.slider2.setRange(0, 99)
          self.slider2.setValue(99)
          vbox.addWidget(self.slider2)
  
          self.slider1.valueChanged.connect(self.slider2Changed)
  
      def slider2Changed(self, position):
          self.slider2.setValue(self.slider2.maximum() - position)
  
  def main():
          app = QApplication(sys.argv)
          w = MyWindow()
          w.show()
          app.exec_()
          sys.exit(0)
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>I do not have errors when running the code using python:</p>
  
  <pre><code>python myexample.py
  </code></pre>
  
  <p>This error only happens when I run the code in an IPython (including a notebook or the qtconsole or the regular ipython terminal).</p>
  
  <p>UPDATE: My main problem is that I cannot run the application again quickly and easily. If I try to run my code again, I get this:</p>
  
  <pre><code>RuntimeError: A QApplication instance already exists.
  </code></pre>
  
  <p>That kills the fast, interactive nature of IPython :(</p>