Skip to content

Commit

Permalink
add -u flag to stream python output
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Jul 2, 2024
1 parent c62850a commit 2c6ed9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func getPythonCommandToRun(builtin *RunPythonCapabilities) (string, error) {
argumentsAsString := strings.Join(maybePythonArgumentsWithRuntimeValueReplaced, spaceDelimiter)
runEscaped := strings.ReplaceAll(builtin.run, `"`, `\"`)
if len(argumentsAsString) > 0 {
return fmt.Sprintf(`python -c "%s" %s`, runEscaped, argumentsAsString), nil
return fmt.Sprintf(`python -u -c "%s" %s`, runEscaped, argumentsAsString), nil
}
return fmt.Sprintf(`python -c "%s"`, runEscaped), nil
return fmt.Sprintf(`python -u -c "%s"`, runEscaped), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ const (
runFilesArtifactsKey = "files_artifacts"

shellWrapperCommand = "/bin/sh"
taskLogFileNamePath = "/tmp/kurtosis/task.log"
taskLogFilePath = "/tmp/kurtosis-task.log"
noNameSet = ""
uniqueNameGenErrStr = "error occurred while generating unique name for the file artifact"

// enables init mode on containers; cleaning up any zombie processes
tiniEnabled = true
)

var runCommandToStreamTaskLogs = []string{shellWrapperCommand, "-c", fmt.Sprintf("touch %s && tail -F %s", taskLogFileNamePath, taskLogFileNamePath)}
var runCommandToStreamTaskLogs = []string{shellWrapperCommand, "-c", fmt.Sprintf("touch %s && tail -F %s", taskLogFilePath, taskLogFilePath)}

// Wraps [commandToRun] to enable streaming logs from tasks.
// Uses curly braces to execute the command(s) in the current shell.
// Adds an extra echo to ensure each log ends with a newline (may add an extra line at the end).
// Uses tee to direct output to the task log file
// Redirects stderr to stdout (can be disabled if not needed).
func getCommandToRunForStreamingLogs(commandToRun string) []string {
return []string{shellWrapperCommand, "-c", fmt.Sprintf("{ %v; } %v %v %v %v %v %v %v %v", commandToRun, "2>&1", "|", "tee", taskLogFileNamePath, "&&", "echo", ">>", taskLogFileNamePath)}
return []string{shellWrapperCommand, "-c", fmt.Sprintf("{ %v; } %v %v %v %v %v %v %v %v", commandToRun, "2>&1", "|", "tee", taskLogFilePath, "&&", "echo", ">>", taskLogFilePath)}
}

func parseStoreFilesArg(serviceNetwork service_network.ServiceNetwork, arguments *builtin_argument.ArgumentValuesSet) ([]*store_spec.StoreSpec, *startosis_errors.InterpretationError) {
Expand Down

0 comments on commit 2c6ed9a

Please sign in to comment.