Commit 8ec800fe authored by Martín Ferrari's avatar Martín Ferrari

Fix some issues with the destruction of half-created processes

parent 08ad1a96
...@@ -55,6 +55,10 @@ class Subprocess(object): ...@@ -55,6 +55,10 @@ class Subprocess(object):
argv = [ argv ] argv = [ argv ]
if shell: if shell:
argv = [ '/bin/sh', '-c' ] + argv argv = [ '/bin/sh', '-c' ] + argv
# Initialize attributes that would be used by the destructor if spawn
# fails
self._pid = self._returncode = None
# confusingly enough, to go to the function at the top of this file, # confusingly enough, to go to the function at the top of this file,
# I need to call it thru the communications protocol: remember that # I need to call it thru the communications protocol: remember that
# happens in another process! # happens in another process!
...@@ -63,7 +67,6 @@ class Subprocess(object): ...@@ -63,7 +67,6 @@ class Subprocess(object):
cwd = cwd, env = env, user = user) cwd = cwd, env = env, user = user)
node._add_subprocess(self) node._add_subprocess(self)
self._returncode = None
@property @property
def pid(self): def pid(self):
...@@ -106,17 +109,17 @@ class Subprocess(object): ...@@ -106,17 +109,17 @@ class Subprocess(object):
def __del__(self): def __del__(self):
self.destroy() self.destroy()
def destroy(self): def destroy(self):
if self._returncode != None: if self._returncode != None or self._pid == None:
return return
self.signal() self.signal()
now = time.time() now = time.time()
while time.time() - now < KILL_WAIT: while time.time() - now < KILL_WAIT:
if self.poll(): if self.poll() != None:
return return
time.sleep(0.1) time.sleep(0.1)
sys.stderr.write("WARNING: killing forcefully process %d.\n" % sys.stderr.write("WARNING: killing forcefully process %d.\n" %
self._pid) self._pid)
self.signal(signal.KILL) self.signal(signal.SIGKILL)
self.wait() self.wait()
PIPE = -1 PIPE = -1
...@@ -137,6 +140,7 @@ class Popen(Subprocess): ...@@ -137,6 +140,7 @@ class Popen(Subprocess):
""" """
self.stdin = self.stdout = self.stderr = None self.stdin = self.stdout = self.stderr = None
self._pid = self._returncode = None
fdmap = { "stdin": stdin, "stdout": stdout, "stderr": stderr } fdmap = { "stdin": stdin, "stdout": stdout, "stderr": stderr }
# if PIPE: all should be closed at the end # if PIPE: all should be closed at the end
for k, v in fdmap.items(): for k, v in fdmap.items():
......
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