Skip to content

Commit

Permalink
Import only specific parts of subprocess module
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Nov 9, 2024
1 parent 648523b commit 545964a
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions rebench/denoise.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
import os
import subprocess
import sys

from argparse import ArgumentParser
from math import log, floor
from multiprocessing import Pool
from subprocess import check_output, CalledProcessError, DEVNULL, STDOUT

from .output import output_as_str, UIError
from .subprocess_kill import kill_process
Expand Down Expand Up @@ -47,22 +47,18 @@ def _absolute_path_for_command(self, command, arguments_for_successful_exe):
"""
try:
selected_cmd = output_as_str(
subprocess.check_output(
[self.get_which(), command], shell=False, stderr=subprocess.DEVNULL
)
check_output([self.get_which(), command], shell=False, stderr=DEVNULL)
).strip()
result_cmd = os.path.realpath(selected_cmd)
except subprocess.CalledProcessError:
except CalledProcessError:
result_cmd = command

try:
subprocess.check_output(
[result_cmd] + arguments_for_successful_exe,
shell=False,
stderr=subprocess.DEVNULL,
check_output(
[result_cmd] + arguments_for_successful_exe, shell=False, stderr=DEVNULL
)
return result_cmd
except (subprocess.CalledProcessError, FileNotFoundError):
except (CalledProcessError, FileNotFoundError):
return False

def has_cset(self):
Expand Down Expand Up @@ -114,9 +110,7 @@ def _can_set_niceness():
our benchmarks.
"""
try:
output = subprocess.check_output(
["nice", "-n-20", "echo", "test"], stderr=subprocess.STDOUT
)
output = check_output(["nice", "-n-20", "echo", "test"], stderr=STDOUT)
output = output_as_str(output)
except OSError:
return False
Expand Down Expand Up @@ -144,9 +138,8 @@ def _activate_shielding(num_cores):
return False

try:
output = subprocess.check_output(
[paths.get_cset(), "shield", "-c", core_spec, "-k", "on"],
stderr=subprocess.STDOUT,
output = check_output(
[paths.get_cset(), "shield", "-c", core_spec, "-k", "on"], stderr=STDOUT
)
output = output_as_str(output)
except OSError:
Expand All @@ -163,14 +156,12 @@ def _activate_shielding(num_cores):

def _reset_shielding():
try:
output = subprocess.check_output(
[paths.get_cset(), "shield", "-r"], stderr=subprocess.STDOUT
)
output = check_output([paths.get_cset(), "shield", "-r"], stderr=STDOUT)
output = output_as_str(output)
return "cset: done" in output
except OSError:
return False
except subprocess.CalledProcessError:
except CalledProcessError:
return False


Expand Down

0 comments on commit 545964a

Please sign in to comment.