From a3279d475178616e0f8280dccbc6c982c9bce74c Mon Sep 17 00:00:00 2001 From: roblanf Date: Wed, 19 Apr 2017 19:12:07 +1000 Subject: [PATCH 1/2] change how we run external programs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2 key things: 1. We pipe stderr to stdout. This just joins the two streams, and hopefully helps avoid zombie processes. The thought is that sometimes the zombies sit waiting for empty stderr/out streams. 2. We don’t use p.communicate unless we have to. We use p.wait() instead. Empirically this seems to offer a modest speedup. --- partfinder/util.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/partfinder/util.py b/partfinder/util.py index 834b251c..fe440fcb 100644 --- a/partfinder/util.py +++ b/partfinder/util.py @@ -31,9 +31,9 @@ class PartitionFinderError(Exception): pass class ExternalProgramError(PartitionFinderError): - def __init__(self, stderr, stdout): - self.stderr = stderr + def __init__(self, stdout, stderr): self.stdout = stdout + self.stderr = stderr class ParseError(PartitionFinderError): pass @@ -74,13 +74,13 @@ def run_program(binary, command): shlex.split(command), shell=False, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.STDOUT) - # Capture the output, we might put it into the errors - stdout, stderr = p.communicate() - # p.terminate() + err = p.wait() - if p.returncode != 0: + if err: + # Capture the output to put into the error + stdout, stderr = p.communicate() raise ExternalProgramError(stdout, stderr) def dupfile(src, dst): From c92c4860a6277a10279c2b415ac36727d8c72f4a Mon Sep 17 00:00:00 2001 From: roblanf Date: Wed, 19 Apr 2017 19:13:03 +1000 Subject: [PATCH 2/2] Don't use stderr in ExternalProgramError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit because it’s empty now. --- partfinder/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/partfinder/main.py b/partfinder/main.py index f785f7ae..53eb9021 100644 --- a/partfinder/main.py +++ b/partfinder/main.py @@ -416,7 +416,6 @@ def main(name, datatype, passed_args=None): log.error("""A program that Partitionfinder uses failed. Output follows, in case it's helpful for finding the problem""") log.error("%s", e.stdout) - log.error("%s", e.stderr) if options.show_python_exceptions or passed_args is not None: raise