How to close a program I execute with subprocess.Popen?

Nick Craig-Wood nick at craig-wood.com
Sun Jul 1 04:30:04 EDT 2007


A.T.Hofkamp <hat at se-162.se.wtb.tue.nl> wrote:
>  In principle, you should only kill your own child processes, your child process
>  should handle its own childs (your grant child processes). SIGTERM is one way.
>  Another solution often adopted is to close the stdin of the child.

That is a good idea.

You could also make the parent a process group leader and kill the
process group.  You'll get the kill signal too which you'll need to
ignore.  That is how the shell keeps track of things IIRC.

Read man setpgid, getpgid should be helful.  There are equivalent
commands in os, ie os.setpgid and os.getpgid.

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list