I am trying to stop a server which is a subprocess when the parent process gets killed by a cntrl-D(EOF on stdin). I tried many ways including reading stdin in the subprocess but that blocks all keyboard input. Is there a way to kill the subprocess when the parent process encounters a EOF.
Creating a subprocess in python via subprocess.Popen
polling for EOF in subprocess by this:
self.t = threading.Thread(target=self.server.serve_forever)
self.t.start()
# quit on cntrl-d (EOF)
while True:
if len(sys.stdin.readline()) == 0:
self.stop()
def stop(self):
manager.save()
# shutdown bottle
self.server.shutdown()
# close socket
self.server.server_close()
self.t.join()
sys.exit()