PyQt5 application not restarting itself

  • So I followed this documentation

    I need to make my software restart after doing some updates but it exists successfully but then doesn't start up anymore.

    My code looks like this:

        def restart(self):

    Note: The function is inside the Main class which inherits from QMainWindow

  • did you really follow that documentation? There is nothing magical about the exit code. you have to check it as a loop condition in main. I don't see enough of your code to know whether you did that.

  • Since python does not have a do while loop, here's something I tried

    if __name__ == '__main__':
        app = QApplication(sys.argv)
        current_exit_code = 0
        while True:
            ex = Main()
            ex.setFont(QFont("Consolas", 10))
            #welcome = Welcome(ex)
            current_exit_code = app.exec()
            if current_exit_code == -123456789:

    That didn't work either

  • Here's what I did to make it work:

     def restart(self):
            os.execl(sys.executable, sys.executable, *sys.argv)

    That simple function will restart the whole script

  • reread the documentation you referenced above. You should instantiate QApplication inside your while loop, not outside.

  • @Fuchsiaff
    That's fine, but it's a totally different kind of application "restart" versus what the code in the link is doing :)

Log in to reply