All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 3/6] test-runner: fix process cleanup
Date: Tue, 07 Sep 2021 09:54:36 -0700	[thread overview]
Message-ID: <20210907165439.9913-3-prestwoj@gmail.com> (raw)
In-Reply-To: <20210907165439.9913-1-prestwoj@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1651 bytes --]

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

  parent reply	other threads:[~2021-09-07 16:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 16:54 [PATCH 1/6] test-runner: remove special case for "root" namespace James Prestwood
2021-09-07 16:54 ` [PATCH 2/6] test-runner: don't use start_process for transient processes James Prestwood
2021-09-07 16:54 ` James Prestwood [this message]
2021-09-07 16:54 ` [PATCH 4/6] test-runner: use Process to start hostapd James Prestwood
2021-09-07 16:54 ` [PATCH 5/6] test-runner: write out separators in log files James Prestwood
2021-09-07 16:54 ` [PATCH 6/6] test-runner: move process tracking out of Namespace James Prestwood
2021-09-07 17:46 ` [PATCH 1/6] test-runner: remove special case for "root" namespace Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210907165439.9913-3-prestwoj@gmail.com \
    --to=prestwoj@gmail.com \
    --cc=iwd@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.