def METHOD_NAME(prevent_garbage_collection=True):
    """Retrieve or create the QApplication instance.
    If running inside Spyder, or if you've used TraitsUI, the application
    will already exist so you can't create another.  However, if you are
    running from the command line you need to create an instance before
    you can do anything.  This function takes care of it - it should always
    return a valid QApplication, unless something goes wrong!
    """
    app = QtWidgets.QApplication.instance()
    if app is None:
        app = QtWidgets.QApplication([])
    assert app is not None, "Problem creating the QApplication."
    if prevent_garbage_collection:
        # Keep a reference to the application if appropriate, to stop
        # it disappearing due to garbage collection.
        global _retained_qt_app
        _retained_qt_app = app
    return app