Restarting a Python Application

Discussion in 'Python' started by kyosohma@gmail.com, Jul 3, 2007.

  1. Guest

    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
     
    , Jul 3, 2007
    #1
    1. Advertising

  2. Matimus Guest

    On Jul 3, 2:27 pm, 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)
    
    
     
    Matimus, Jul 3, 2007
    #2
    1. Advertising

  3. Guest

    On Jul 3, 5:00 pm, Matimus <> wrote:
    > On Jul 3, 2:27 pm, 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)
    >
    > 


    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
     
    , Jul 6, 2007
    #3
  4. Matimus Guest


    > 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.


    I don't know wxPython, but I was able to grab an example program and
    adapt it to do what I think you are asking for.
    Something like this:

    Code:
    #! /usr/bin/env python
    
    from wxPython import wx
    
    ID_EXIT  = 101
    ID_RST   = 102
    
    class MyFrame(wx.wxFrame):
        def __init__(self, parent, ID, title):
            wx.wxFrame.__init__(self, parent, ID, title,
                             wx.wxDefaultPosition, wx.wxSize(200, 150))
            self.CreateStatusBar()
            self.SetStatusText("This is the statusbar")
    
            menu = wx.wxMenu()
            menu.Append(ID_EXIT, "E&xit", "Terminate the program")
            menu.Append(ID_RST, "&Restart", "Restart the program")
    
            menuBar = wx.wxMenuBar()
            menuBar.Append(menu, "&File");
    
            self.SetMenuBar(menuBar)
    
            wx.EVT_MENU(self, ID_EXIT,  self.TimeToQuit)
            wx.EVT_MENU(self, ID_RST,  self.TimeToRestart)
    
        def TimeToQuit(self, e):
            self.Close(wx.true)
    
        def TimeToRestart(self, e):
            global restart
            restart = True
            self.TimeToQuit(e)
    
    
    class MyApp(wx.wxApp):
        def OnInit(self):
            global restart
            restart = False
            frame = MyFrame(wx.NULL, -1, "Hello from wxPython")
            frame.Show(wx.true)
            self.SetTopWindow(frame)
            return wx.true
    
    if __name__ == "__main__":
        MyApp(0).MainLoop()
        while restart:
            MyApp(0).MainLoop()
    
    
     
    Matimus, Jul 7, 2007
    #4
  5. Kelvie Wong Guest

    Ugh.. this would be a repost for the OP, but I forgot to hit "reply to
    all" again.

    This should do it:

    os.execv(sys.argv[0], sys.argv)

    Not sure how portable that statement is, though.


    On 7/3/07, <> 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
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >



    --
    Kelvie
     
    Kelvie Wong, Jul 7, 2007
    #5
  6. Peter Decker Guest

    On 7/7/07, Kelvie Wong <> wrote:
    > Ugh.. this would be a repost for the OP, but I forgot to hit "reply to
    > all" again.


    <rant>
    Imagine if you wrote applications where the default behavior did not
    do what was needed 99% of the time: how long do you think you'd be in
    business?

    The default behavior of replying to the original sender instead of the
    list makes no sense. I've read the purist arguments against replying
    to the list, but I subscribed to a *list*, not an individual sender.

    I know that this post is pointless, since the people who run this list
    seem to care more about abstract and misdirected notions of purity
    than making things as useful and intelligent as possible, but after
    seeing dozens of "please keep your reply on list" responses recently,
    I had to vent.
    </rant>
    --

    # p.d.
     
    Peter Decker, Jul 8, 2007
    #6
  7. Steve Holden Guest

    Peter Decker wrote:
    > On 7/7/07, Kelvie Wong <> wrote:
    >> Ugh.. this would be a repost for the OP, but I forgot to hit "reply to
    >> all" again.

    >
    > <rant>
    > Imagine if you wrote applications where the default behavior did not
    > do what was needed 99% of the time: how long do you think you'd be in
    > business?
    >
    > The default behavior of replying to the original sender instead of the
    > list makes no sense. I've read the purist arguments against replying
    > to the list, but I subscribed to a *list*, not an individual sender.
    >
    > I know that this post is pointless, since the people who run this list
    > seem to care more about abstract and misdirected notions of purity
    > than making things as useful and intelligent as possible, but after
    > seeing dozens of "please keep your reply on list" responses recently,
    > I had to vent.
    > </rant>


    Well, I hope you feel better now.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://del.icio.us/steve.holden
    --------------- Asciimercial ------------------
    Get on the web: Blog, lens and tag the Internet
    Many services currently offer free registration
    ----------- Thank You for Reading -------------
     
    Steve Holden, Jul 8, 2007
    #7
  8. Ben Finney Guest

    Broken MUA interactions (was: Restarting a Python Application)

    "Peter Decker" <> writes:

    > Imagine if you wrote applications where the default behavior did not
    > do what was needed 99% of the time: how long do you think you'd be
    > in business?


    You seem to be complaining about the functionality of your mail user
    agent (MUA) software. The mailing list processor is doing its job
    fine.

    There are at least two "compose a reply" functions supported by every
    MUA. Use the one that does what you want in each instance.

    If you use the "Reply to individual sender" function, that's what you
    get.

    If you use the "Reply to all" function, that's what you get.

    If you use the "Reply to the list" function, that's what you get.

    > The default behavior of replying to the original sender instead of
    > the list makes no sense.


    The mailing list software provides your MUA with all the information
    it needs to do what you want: the 'From' address as set by the
    original poster, the 'Reply-To' address as set by the original poster,
    the 'To' and 'Cc' addresses as set by the original poster, and the
    'List-Post' address as set by the mailing list software. All of these
    are standard message header fields with well-defined functions, and
    can be used as-is to do what you need.

    If your MUA isn't using this information correctly, the solution is to
    fix the MUA (by choosing a better one or encouraging the maker of your
    existing one to fix it), not to munge those fields to accomodate your
    broken MUA.

    --
    \ "Dyslexia means never having to say that you're ysror." -- |
    `\ Anonymous |
    _o__) |
    Ben Finney
     
    Ben Finney, Jul 8, 2007
    #8
  9. Chris Mellon Guest

    Re: Broken MUA interactions (was: Restarting a Python Application)

    On 7/8/07, Ben Finney <> wrote:
    > "Peter Decker" <> writes:
    >
    > > Imagine if you wrote applications where the default behavior did not
    > > do what was needed 99% of the time: how long do you think you'd be
    > > in business?

    >
    > You seem to be complaining about the functionality of your mail user
    > agent (MUA) software. The mailing list processor is doing its job
    > fine.
    >


    It's working as instructed, but that doesn't mean that it's doing the
    best thing. It's common practice for mailing lists to set the reply-to
    to the list itself, because that's the common case, and because it's
    encouraged to keep discussion on the list.

    If whoever manages the python lists doesn't want to do it, either
    because they have some practical reason or because they've got a bug
    up their ass about mail readers without list support, thats fine. But
    it's hardly incorrect to configure it with the reply-to set to the
    list, either.
     
    Chris Mellon, Jul 9, 2007
    #9
  10. Re: Broken MUA interactions (was: Restarting a Python Application)

    En Mon, 09 Jul 2007 10:48:39 -0300, Chris Mellon <>
    escribió:

    > It's working as instructed, but that doesn't mean that it's doing the
    > best thing. It's common practice for mailing lists to set the reply-to
    > to the list itself, because that's the common case, and because it's
    > encouraged to keep discussion on the list.
    >
    > If whoever manages the python lists doesn't want to do it, either
    > because they have some practical reason or because they've got a bug
    > up their ass about mail readers without list support, thats fine. But
    > it's hardly incorrect to configure it with the reply-to set to the
    > list, either.


    No, it's not correct to modify Reply-To. Some reasons:
    http://www.unicom.com/pw/reply-to-harmful.html

    --
    Gabriel Genellina
     
    Gabriel Genellina, Jul 9, 2007
    #10
  11. Chris Mellon Guest

    Re: Broken MUA interactions (was: Restarting a Python Application)

    On 7/9/07, Gabriel Genellina <> wrote:
    > En Mon, 09 Jul 2007 10:48:39 -0300, Chris Mellon <>
    > escribió:
    >
    > > It's working as instructed, but that doesn't mean that it's doing the
    > > best thing. It's common practice for mailing lists to set the reply-to
    > > to the list itself, because that's the common case, and because it's
    > > encouraged to keep discussion on the list.
    > >
    > > If whoever manages the python lists doesn't want to do it, either
    > > because they have some practical reason or because they've got a bug
    > > up their ass about mail readers without list support, thats fine. But
    > > it's hardly incorrect to configure it with the reply-to set to the
    > > list, either.

    >
    > No, it's not correct to modify Reply-To. Some reasons:
    > http://www.unicom.com/pw/reply-to-harmful.html
    >


    None of those are reasons, they're opinions and weary old excuses. I'm
    not necessarily saying munging is the correct thing to do (although,
    personally, I support it and would prefer if the python lists did it)
    but it's about a clash of opinions about what cases and behaviors
    should be supported and encouraged. Since it's obviously not my call
    as I'm not the admin of the python lists I adjust to what the list
    does, but claiming that people asking for the other behavior are
    incorrect or out of line in some way is just unjustified.
     
    Chris Mellon, Jul 9, 2007
    #11
  12. Ben Finney Guest

    Re: Broken MUA interactions

    "Gabriel Genellina" <> writes:

    > No, it's not correct to modify Reply-To. Some reasons:
    > http://www.unicom.com/pw/reply-to-harmful.html


    Not to mention that, since the publication of that document, it's now
    even more clearly incorrect to munge 'reply-to' fields; the standards
    now specify exactly what that field is for.

    <URL:http://woozle.org/~neale/papers/reply-to-still-harmful.html>

    --
    \ "Teach a man to make fire, and he will be warm for a day. Set a |
    `\ man on fire, and he will be warm for the rest of his life." -- |
    _o__) John A. Hrastar |
    Ben Finney
     
    Ben Finney, Jul 10, 2007
    #12
  13. Ben Finney Guest

    Re: Broken MUA interactions

    "Chris Mellon" <> writes:

    > On 7/9/07, Gabriel Genellina <> wrote:
    > > No, it's not correct to modify Reply-To. Some reasons:
    > > http://www.unicom.com/pw/reply-to-harmful.html

    >
    > None of those are reasons, they're opinions and weary old excuses.


    They're old, but not weary, because they're now supported by the
    internet message standards, which spell out exactly what Reply-To and
    List-Post are for.

    <URL:http://woozle.org/~neale/papers/reply-to-still-harmful.html>

    Reply-To, if used, is to be set by the message author. Since a
    message transport system may only add fields to the header, not
    arbitrarily modify existing fields, Reply-To can't be munged.
    <URL:http://www.ietf.org/rfc/rfc2822.txt>

    List-Post is to be used to give the email address for posting
    messages to the mailing list.
    <URL:http://www.ietf.org/rfc/rfc2369.txt>

    Please, let's stop arguing what's already been decided. Every
    behaviour you ask for is already supported by the existing
    standards. The "common case" you speak of is fully supported by the
    unambiguous List-Post field.

    If your MUA is not using the information, provided in every message
    from the mailing list, to do what you want, don't ask mailing list
    admmministrators to accomodate your broken MUA.

    --
    \ "Pinky, are you pondering what I'm pondering?" "I think so, |
    `\ Brain, but culottes have a tendency to ride up so." -- _Pinky |
    _o__) and The Brain_ |
    Ben Finney
     
    Ben Finney, Jul 10, 2007
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LJ
    Replies:
    0
    Views:
    1,138
  2. Bosh
    Replies:
    0
    Views:
    751
  3. Hari Koduru
    Replies:
    3
    Views:
    1,394
    Natty Gur
    Jan 15, 2004
  4. Jordan R.

    Restarting ASP.NET Web Application

    Jordan R., Nov 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,637
    Juan T. Llibre
    Nov 16, 2005
  5. Stephen
    Replies:
    2
    Views:
    1,284
    Stephen
    Mar 1, 2006
Loading...

Share This Page