Skip to content

Commit

Permalink
improved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbog committed Jun 2, 2024
1 parent e7438e6 commit 89a9d21
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion benchkit/shell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ def shell_out(
str: the output of the shell command that completed successfully.
"""

#this will run the true command confirming the exit code instead of assuming it
completedProcess = subprocess.run(["true"], timeout=None)
sucsess_value = completedProcess.returncode
def sucsess(value):
return value == sucsess_value


print_arguments = get_args(command)
print_header(
arguments=print_arguments,
Expand All @@ -140,9 +142,20 @@ def sucsess(value):
asynced=False,
remote_host=None,
)

#splitting our command as needed
arguments = get_args(command) if (split_arguments) else command


def flush_outlines(process):
"""
prints and returns the current content of stdout for a given process
Args:
process (Popen):
process to log
Returns:
str: content of stdout.
"""
outlines = []
outline = process.stdout.readline()
while outline:
Expand All @@ -152,6 +165,16 @@ def flush_outlines(process):
return outlines

def flush_thread(process,output):
"""
while process is running will log and store all stdout in real time
Args:
process (Popen):
process to log
output (Value(c_char_p)):
manager value to write result to
Returns:
None
"""
outlines = []
retcode = process.poll()
while retcode is None:
Expand All @@ -173,8 +196,12 @@ def flush_thread(process,output):
) as shell_process:
if output_is_log:
try:
"""
logging the process takes two threads since we need to wait for the timeout while logging stdout in real time
to accomplish this we use multiprocessing in combination with error catching to interupt the logging if needed
"""
manager = Manager()
output_logger_process = manager.Value(c_char_p, "Hello")
output_logger_process = manager.Value(c_char_p, "")
logger_process = Process(target=flush_thread, args=(shell_process,output_logger_process,))
logger_process.start()
retcode = shell_process.wait(timeout=timeout)
Expand Down
4 changes: 2 additions & 2 deletions benchkit/shell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys
import tempfile
from typing import Optional
from shlex import split
import shlex

from benchkit.utils.types import Command, Environment, PathType, SplitCommand

Expand All @@ -27,7 +27,7 @@ def get_args(command: Command) -> SplitCommand:
SplitCommand: the split command.
"""
if isinstance(command, str):
arguments = split(command)
arguments = shlex.split(command)
else:
arguments = command
return arguments
Expand Down

0 comments on commit 89a9d21

Please sign in to comment.