subprocess leaves child living
reedobrien at gmail.com
Thu Jun 7 09:00:53 CEST 2007
On Jun 5, 7:58 am, Thomas Dybdahl Ahle <lob... at gmail.com> wrote:
> Hi, When I do a small program like
> from subprocess import Popen
> popen = Popen(["ping", "google.com"])
> from time import sleep
> start it and kill it, the ping process lives on.
> Is there a way to ensure that the ping process is always killed when the
> python process is?
> I can't use atexit, as ping then isn't killed when python is killed "in
> the hard way"
pid = popen.pid
pidfile = open('/usr/local/var/somefile.pid', 'w')
then you can check if it is still running when your ?program? restarts
and can kill it.
maybe not the perfect answer, but it answers an imperfect question.
More information about the Python-list