Can python subprocess pipe reattach to original child process when program restart? -
i looking safe way restart python program able regain control of child process launched before restart.
i use subprocess thread monitor stdout
/stderr
of long run command
continuously generate output message.
the sample code snippet follow:
class ps(threading.thread): def __init__(self, command): threading.thread.__init__(self) self.command = command def run(self): try: process = subprocess.popen(self.command, shell=true, stdout=subprocess.pipe, stderr=subprocess.stdout) line in iter(process.stdout.readline, ''): ''' line'''
when python main program terminated (kill pid example), child process (the command
executed ps
class) still alive background process.
my question is, there way in python "reattach" child process can keep monitoring stdout
/stderr
?
p.s. need in linux environment, more in ubuntu 14.04.
when standard output of child tied pipe, child receive sigpipe signal if tries write pipe after parent dies, since remote end of pipe no longer exists.
to ensure child survives parent, , allow parent resume, should write file , have parent read file instead.
Comments
Post a Comment