code: def initialize():
      
      # This doesn't create our QApplication, just holds a reference to
      # MAIN_APP, created above to show our splash screen as early as
      # possible
      app = qapplication()
  
      # --- Set application icon
      app.setWindowIcon(APP_ICON)
  
      #----Monkey patching QApplication
      class FakeQApplication(QApplication):
          """Spyder's fake QApplication"""
          def __init__(self, args):
              self = app  # analysis:ignore
          @staticmethod
          def exec_():
              """Do nothing because the Qt mainloop is already running"""
              pass
      from qtpy import QtWidgets
      QtWidgets.QApplication = FakeQApplication
  
      # ----Monkey patching sys.exit
      def fake_sys_exit(arg=[]):
          pass
      sys.exit = fake_sys_exit
  
      # ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
      if PYQT5:
          def spy_excepthook(type_, value, tback):
              sys.__excepthook__(type_, value, tback)
          sys.excepthook = spy_excepthook
  
      # Removing arguments from sys.argv as in standard Python interpreter
      sys.argv = ['']
  
      # Selecting Qt4 backend for Enthought Tool Suite (if installed)
      try:
          from enthought.etsconfig.api import ETSConfig
          ETSConfig.toolkit = 'qt4'
      except ImportError:
          pass
  
      return app
docs: Initialize Qt, patching sys.exit and eventually setting up ETS