monitoring/restarting an application

G

Ghirai

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

Marco Mariani

Ghirai said:
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
 
G

Giampaolo Rodola'

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.


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top