1

I need to write a process wrapper in python that will launch an application and restart it if it fails. This will be logged to an specified log location passed in from command line. Is this possible?

Sean Vieira
161k34 gold badges321 silver badges297 bronze badges
asked Sep 1, 2011 at 16:58
2

2 Answers 2

1
>>> from subprocess import Popen
>>> def spawner(cmd_list):
... while True:
... print "Running proc..."
... mon_proc = Popen(cmd_list)
... print "Proc exit: %s" % mon_proc.wait()
... 
>>> spawner(['/bin/sleep', '3'])
Running proc...
Proc exit: 0
Running proc...
Proc exit: 0
Running proc...
Proc exit: 0
Running proc...
answered Sep 1, 2011 at 17:41
Sign up to request clarification or add additional context in comments.

Comments

1

Use the subprocess module. Use Popen to start it and get a Popen objet. Use Popen.poll() or wait to get process status depending of what you want. Do it in a loop, and log using the logging module.

my 2 cents

answered Sep 1, 2011 at 17:08

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.