3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

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.
This commit is contained in:
James Prestwood 2021-09-07 09:54:36 -07:00 committed by Denis Kenzior
parent 920dc5b087
commit 165557070e

View File

@ -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'