Restarting a Python Application

kyosohma at gmail.com kyosohma at gmail.com
Fri Jul 6 20:34:27 CEST 2007


On Jul 3, 5:00 pm, Matimus <mccre... at gmail.com> wrote:
> On Jul 3, 2:27 pm, kyoso... at gmail.com wrote:
>
>
>
> > Hi,
>
> > I packaged up an application I am developing into an executable. In
> > the application, it has user configurable options. I would like a way
> > to restart the application so that the new options the user chooses
> > can be applied. Firefox can restart itself. Does anyone know how to
> > accomplish this in Python?
>
> > Here is what I tried:
>
> > <code>
>
> > exePath = os.path.join(os.getcwd(), 'myprogram.exe')
> > subprocess.Popen(exePath)
> > sys.exit()
>
> > </code>
>
> > This didn't work. It closed the program, but another instance did not
> > appear.
>
> > Tips would be appreciated.
>
> > Mike
>
> You could package your program into a function or class and just
> restart that.
>
> [code]
> # global flag for restart.
> do_restart = False
>
> def main(args=None):
>     # program code
>     # set do_restart and return to restart
>
> if __name__ == "__main__":
>     retval = main()
>     while do_restart:
>         retval = main()
>     sys.exit(retval)
>
> [/code]

Actually I am using wxPython for a GUI front-end. Thus, it is already
in a class. I am not sure how to apply your idea to a program that is
already running in an infinite event loop.

Mike




More information about the Python-list mailing list