Commit d0d3ea07 authored by Martín Ferrari's avatar Martín Ferrari

Killing procs on destroy

parent 0c2fe63b
...@@ -27,9 +27,9 @@ class Node(object): ...@@ -27,9 +27,9 @@ class Node(object):
Node._nextnode += 1 Node._nextnode += 1
def __del__(self): def __del__(self):
self.shutdown() self.destroy()
def shutdown(self): def destroy(self):
for p in self._processes.values(): for p in self._processes.values():
p.destroy() p.destroy()
del self._processes del self._processes
......
#!/usr/bin/env python #!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4 # vim:ts=4:sw=4:et:ai:sts=4
import fcntl, grp, os, pickle, pwd, signal, select, sys, traceback import fcntl, grp, os, pickle, pwd, signal, select, sys, time, traceback
__all__ = [ 'PIPE', 'STDOUT', 'Popen', 'Subprocess', 'spawn', 'wait', 'poll', __all__ = [ 'PIPE', 'STDOUT', 'Popen', 'Subprocess', 'spawn', 'wait', 'poll',
'system', 'backticks', 'backticks_raise' ] 'system', 'backticks', 'backticks_raise' ]
# User-facing interfaces # User-facing interfaces
KILL_WAIT = 3 # seconds
class Subprocess(object): class Subprocess(object):
"""Class that allows the execution of programs inside a netns Node. This is """Class that allows the execution of programs inside a netns Node. This is
the base class for all process operations, Popen provides a more high level the base class for all process operations, Popen provides a more high level
...@@ -101,10 +103,21 @@ class Subprocess(object): ...@@ -101,10 +103,21 @@ class Subprocess(object):
return os.WEXITSTATUS(self._returncode) return os.WEXITSTATUS(self._returncode)
raise RuntimeError("Invalid return code") # pragma: no cover raise RuntimeError("Invalid return code") # pragma: no cover
# FIXME: do we have any other way to deal with this than having explicit def __del__(self):
# destroy? self.destroy()
def destroy(self): def destroy(self):
pass if self._returncode != None:
return
self.signal()
now = time.time()
while time.time() - now < KILL_WAIT:
if self.poll():
return
time.sleep(0.1)
sys.stderr.write("WARNING: killing forcefully process %d.\n" %
self._pid)
self.signal(signal.KILL)
self.wait()
PIPE = -1 PIPE = -1
STDOUT = -2 STDOUT = -2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment