subprocess leaves child living

reed reedobrien at gmail.com
Thu Jun 7 03:00:53 EDT 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
> sleep(100)
>
> 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')
pidfile.write('pid')
pidfile.close()


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 mailing list