diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2021-06-10 11:01:49 -0400 |
---|---|---|
committer | BryanQuigley <code@bryanquigley.com> | 2021-06-16 00:15:23 -0700 |
commit | 97fe07beca294f9aba0a98d1d7dcf769f1b825c3 (patch) | |
tree | b7041bedb6cf9cfe3e3674fcfe14c0ab271c2a48 | |
parent | bebb66861a00e57a767029c6725a0b941b784b5f (diff) | |
download | sos-97fe07beca294f9aba0a98d1d7dcf769f1b825c3.tar.gz |
[report] Increase readability and reliability of top-level ThreadPool
In the "top-level" `ThreadPoolExecutor` used for threading plugin
execution, increase readability and reliability by wrapping it in a
`with` context manager, so that the pool's cleanup is run in all
situations explicitly.
This is a continuation of #2294, bringing it up to date with the current
state of the project and iterating over the plugin list as a discreet
unit rather than individual plugins.
Closes: #2294
Resolves: #2578
Co-authored-by: Erik Bernoth <ebernoth@redhat.com>
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/report/__init__.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/sos/report/__init__.py b/sos/report/__init__.py index 2cedc76e..79c1dae0 100644 --- a/sos/report/__init__.py +++ b/sos/report/__init__.py @@ -969,11 +969,10 @@ class SoSReport(SoSComponent): plugruncount += 1 self.pluglist.append((plugruncount, i[0])) try: - self.plugpool = ThreadPoolExecutor(self.opts.threads) - # Pass the plugpool its own private copy of self.pluglist - results = self.plugpool.map(self._collect_plugin, - list(self.pluglist)) - self.plugpool.shutdown(wait=True) + results = [] + with ThreadPoolExecutor(self.opts.threads) as executor: + results = executor.map(self._collect_plugin, + list(self.pluglist)) for res in results: if not res: self.soslog.debug("Unexpected plugin task result: %s" % |