simple IPython example raises exception on sys.exit()

前端 未结 5 859
一个人的身影
一个人的身影 2020-12-01 14:55

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.

When I clo

5条回答
  •  孤城傲影
    2020-12-01 15:32

    This answer is thanks to Matthias BUSSONNIER from the ipython-users mailing list.

    When I close the window of the running demo application, I see this error: An exception has occurred, use %tb to see the full traceback. SystemExit: 0

    Just don't use sys.exit(0) as you are not exiting python, but still running IPython.

    Add it back if you wish to run your app from a (real) command line and have a return status.

    If I try to execute my code again, I get this:
    RuntimeError: A QApplication instance already exists.

    This is a PySide Bug that they "won't fix" as they don't consider it a bug.

    See https://github.com/ipython/ipython/issues/1124)
    and http://bugs.pyside.org/show_bug.cgi?id=855

    QApplication can only have one instance and quitting an app is apparently not considered a reason sufficient enough do delete the object...

    You can use this code from above issues :

    app=QtGui.QApplication.instance() # checks if QApplication already exists 
    if not app: # create QApplication if it doesnt exist 
         app = QtGui.QApplication(sys.argv)
    

    This was a sufficient solution for my present needs.

提交回复
热议问题