From 165557070e1bfc032acac6ad0fc0e48408e9de41 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Tue, 7 Sep 2021 09:54:36 -0700 Subject: [PATCH] test-runner: fix process cleanup Processes which were not explicitly killed ended up staying around forever because they internally held references to other objects such as GLib IO watches or write FDs. This shuffles some code so these objects get cleaned up both when explititly killed and after being waited for. --- tools/test-runner | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/test-runner b/tools/test-runner index 34fdb74a..fb52c57c 100755 --- a/tools/test-runner +++ b/tools/test-runner @@ -287,7 +287,23 @@ class Process(subprocess.Popen): # Override wait() so it can do so non-blocking def wait(self, timeout=10): Namespace.non_block_wait(self.__wait, timeout, 1) + self._cleanup() + def _cleanup(self): + if self.cleanup: + self.cleanup() + + self.write_fds = [] + + if self.io_watch: + GLib.source_remove(self.io_watch) + self.io_watch = None + + self.cleanup = None + self.killed = True + + if self in self.ctx.processes: + self.ctx.processes.remove(self) # Override kill() def kill(self, force=False): if self.killed: @@ -306,20 +322,7 @@ class Process(subprocess.Popen): dbg("Process %s did not complete in 15 seconds!" % self.name) super().kill() - if self.cleanup: - self.cleanup() - - self.write_fds = [] - - if self.io_watch: - GLib.source_remove(self.io_watch) - self.io_watch = None - - self.cleanup = None - self.killed = True - - if self in self.ctx.processes: - self.ctx.processes.remove(self) + self._cleanup() def __str__(self): return str(self.args) + '\n'