Created
December 2, 2008 23:53
-
-
Save atifaziz/31343 to your computer and use it in GitHub Desktop.
Google Code Project Downloads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Process Monitor | |
# | |
# Re-launches a process if it dies. | |
# | |
# Public Domain | |
# http://en.wikipedia.org/wiki/Public_domain | |
# Written by | |
# Atif Aziz, http://www.raboof.com | |
# Adapted from | |
# http://bartdesmet.net/blogs/bart/archive/2006/08/30/4366.aspx | |
# | |
# NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
import sys | |
from System import Console | |
from System.Diagnostics import Process, ProcessStartInfo | |
def launch(binpath, args): | |
psi = ProcessStartInfo(FileName = binpath, Arguments = args) | |
proc = Process(StartInfo = psi, UseShellExecute = False, EnableRaisingEvents = True) | |
def onexit(sender, event_args): | |
print 'Process %d stopped. Re-starting...' % proc.Id | |
launch(binpath, args) | |
proc.Exited += onexit | |
proc.Start() | |
print 'Process %d started' % proc.Id | |
def main(args): | |
if not args: | |
raise Exception('Missing path to executable.') | |
launch(args[0], ' '.join(['"%s"' % arg for arg in args[1:]])) | |
Console.ReadLine() | |
if __name__ == '__main__': | |
try: | |
main(sys.argv[1:]) | |
except Exception, e: | |
print >> sys.stderr, e | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment