Den Tue, 05 Jun 2007 07:06:15 -0700 skrev Rob Wolfe: > Thomas Dybdahl Ahle wrote: > >> Problem is - I can't do that when I get killed. Isn't it possible to >> open processes in such a way like terminals? If I kill the terminal, >> everything open in it will die too. > > On POSIX platform you can use signals and ``os.kill`` function. Fo > example: > > <code> > import os, signal > from subprocess import Popen > from time import sleep > > def handler(signum, frame): > print 'Signal handler called' > raise KeyboardInterrupt > > signal.signal(signal.SIGTERM, handler) > > try: > popen = Popen(["ping", "google.com"]) try: > sleep(100) > except KeyboardInterrupt: > pass > finally: > if popen.poll() is None: > print "killing process: %d" % popen.pid os.kill(popen.pid, > signal.SIGTERM) > </code>
But you can't ever catch sigkill. Isn't there a way to make sure the os kills the childprocess when the parrent dies? -- http://mail.python.org/mailman/listinfo/python-list