Your code spawns the process right? I am just suggesting that your
code also clean it up...
class ProcWithCleanup:
def __init__(self):
self.proc = None
def spawn(self, cmd):
self.proc = subprocess.Popen([cmd],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
shell=True)
return self.proc.communicate()[0].strip('\n')
def kill(self):
self.proc.signal(signal.KILL)
def __del__(self):
if not self.proc is None:
self.kill()
demo:
ProcWithCleanup().spawn('watch -n 5 echo "aaa"')
demo2:
p = ProcWithCleanup()
print p.spawn('watch -n 5 echo "aaa"')
p.kill()
As soon as the ProcWithCleanup instance goes out of scope the __del__
deconstructor fires killing the child proc. Or, you can explicitly
kill with the kill() method of said instance.
The example is very simplistic, I mean to only convey how you could
use a deconstructor to do your bidding (killing).
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.