I am writing a python program that lauches a subprocess (using Popen). I am reading stdout of the subprocess, doing some filtering, and writing to stdout of main process.
You can use python atexit module.
atexit
For example:
import atexit def killSubprocess(): mySubprocess.kill() atexit.register(killSubprocess)