monitoring/restarting an application

Discussion in 'Python' started by Ghirai, Mar 5, 2009.

  1. Ghirai

    Ghirai Guest

    Hello list,

    I need to keep x number of instances of an external applications
    running, say /bin/x, but also kill and restart each one after y seconds.

    What would be the best way to do this (with python 2.5.x)?

    I'm thinking of having a list of running pids, then have a thread check
    if len(list) < x, and if it is, then start a new process (with
    os.spawnv?) and add it to the list.
    Also in the list i'd keep PIDs and some sort of started-timestamp, so i
    know which to kill.

    Does this sound reasonable, or is there an easier way?

    Thanks.

    --
    Regards,
    Ghirai.
     
    Ghirai, Mar 5, 2009
    #1
    1. Advertising

  2. Ghirai wrote:

    > I need to keep x number of instances of an external applications
    > running, say /bin/x, but also kill and restart each one after y seconds.
    >
    > What would be the best way to do this (with python 2.5.x)?


    easy_install supervisor

    it should do everything for you
     
    Marco Mariani, Mar 5, 2009
    #2
    1. Advertising

  3. Ghirai

    Paul Rubin Guest

    Ghirai <> writes:
    > Does this sound reasonable, or is there an easier way?


    Use something like daemontools or upstart. Don't roll your own.
     
    Paul Rubin, Mar 5, 2009
    #3
  4. Ghirai

    Ghirai Guest

    On 05 Mar 2009 07:44:44 -0800
    Paul Rubin <http://> wrote:

    > Ghirai <> writes:
    > > Does this sound reasonable, or is there an easier way?

    >
    > Use something like daemontools or upstart. Don't roll your own.
    > --


    Alright, i'll have a look at those as well as supervisor.
    Thanks.

    --
    Regards,
    Ghirai.
     
    Ghirai, Mar 5, 2009
    #4
  5. On 5 Mar, 15:37, Ghirai <> wrote:
    > Hello list,
    >
    > I need to keep x number of instances of an external applications
    > running, say /bin/x, but also kill and restart each one after y seconds.
    >
    > What would be the best way to do this (with python 2.5.x)?
    >
    > I'm thinking of having a list of running pids, then have a thread check
    > if len(list) < x, and if it is, then start a new process (with
    > os.spawnv?) and add it to the list.
    > Also in the list i'd keep PIDs and some sort of started-timestamp, so i
    > know which to kill.
    >
    > Does this sound reasonable, or is there an easier way?
    >
    > Thanks.
    >
    > --
    > Regards,
    > Ghirai.



    Maybe you might want to take a look at psutil [1].
    Rather than looking for PID->timestamp you can look for something else
    like PID->cmdline or PID->executable_name.
    Example:

    import psutil
    for process in psutil.process_iter():
    if (process.pid > 1000) and (process.name ==
    'your_executable_name'):
    process.kill()
    # restart your process here
    # ...


    [1] http://code.google.com/p/psutil

    --- Giampaolo
    http://code.google.com/p/pyftpdlib
     
    Giampaolo Rodola', Mar 6, 2009
    #5
    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,135
  2. Bosh
    Replies:
    0
    Views:
    750
  3. Hari Koduru
    Replies:
    3
    Views:
    1,387
    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,611
    Juan T. Llibre
    Nov 16, 2005
  5. Stephen
    Replies:
    2
    Views:
    1,282
    Stephen
    Mar 1, 2006
Loading...

Share This Page