<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import signal <EOL> import time <EOL> class PidProxy : <EOL> pid = None <EOL> def __init__ ( self , args ) : <EOL> self . setsignals ( ) <EOL> try : <EOL> self . pidfile , cmdargs = args [ <NUM_LIT:1> ] , args [ <NUM_LIT:2> : ] <EOL> self . command = os . path . abspath ( cmdargs [ <NUM_LIT:0> ] ) <EOL> self . cmdargs = cmdargs <EOL> except ( ValueError , IndexError ) : <EOL> self . usage ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def go ( self ) : <EOL> self . pid = os . spawnv ( os . P_NOWAIT , self . command , self . cmdargs ) <EOL> while <NUM_LIT:1> : <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> try : <EOL> pid , sts = os . waitpid ( - <NUM_LIT:1> , os . WNOHANG ) <EOL> except OSError : <EOL> pid , sts = None , None <EOL> if pid : <EOL> break <EOL> def usage ( self ) : <EOL> print "<STR_LIT>" <EOL> def setsignals ( self ) : <EOL> signal . signal ( signal . SIGTERM , self . passtochild ) <EOL> signal . signal ( signal . SIGHUP , self . passtochild ) <EOL> signal . signal ( signal . SIGINT , self . passtochild ) <EOL> signal . signal ( signal . SIGUSR1 , self . passtochild ) <EOL> signal . signal ( signal . SIGUSR2 , self . passtochild ) <EOL> signal . signal ( signal . SIGCHLD , self . reap ) <EOL> def reap ( self , sig , frame ) : <EOL> pass <EOL> def passtochild ( self , sig , frame ) : <EOL> try : <EOL> pid = int ( open ( self . pidfile , '<STR_LIT:r>' ) . read ( ) . strip ( ) ) <EOL> except : <EOL> pid = None <EOL> print "<STR_LIT>" % self . pidfile <EOL> return <EOL> os . kill ( pid , sig ) <EOL> if sig in [ signal . SIGTERM , signal . SIGINT , signal . SIGQUIT ] : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> def main ( ) : <EOL> pp = PidProxy ( sys . argv ) <EOL> pp . go ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
