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):
Node._nextnode += 1
def __del__(self):
self.shutdown()
self.destroy()
def shutdown(self):
def destroy(self):
for p in self._processes.values():
p.destroy()
del self._processes
......
#!/usr/bin/env python
# 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',
'system', 'backticks', 'backticks_raise' ]
# User-facing interfaces
KILL_WAIT = 3 # seconds
class Subprocess(object):
"""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
......@@ -101,10 +103,21 @@ class Subprocess(object):
return os.WEXITSTATUS(self._returncode)
raise RuntimeError("Invalid return code") # pragma: no cover
# FIXME: do we have any other way to deal with this than having explicit
# destroy?
def __del__(self):
self.destroy()
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
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