Created
October 21, 2019 17:55
-
-
Save Fogapod/7b55095c3b5968a480224acb31946999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
for i in range(5): | |
time.sleep(1) | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Description: | |
# This script runs provided command with timeout sending output to directory. | |
# | |
# Env variables: | |
# TIMEOUT: | |
# Timeout for execution in seconds. Defaults to 30. | |
# OUT_DIR: | |
# Directory that is used for results such as stdout, stderr, execution time, | |
# exit code. | |
# | |
# Usage: | |
# ./run_entrypoint.sh <arguments> | |
# | |
# Example: | |
# ./run_entrypoint.sh python main.py | |
# | |
# TODO: compilation | |
set -e | |
TIMEOUT=${TIMEOUT:-30} | |
OUT_DIR=${OUT_DIR:?Variable not set} | |
STDOUT_FILE=$OUT_DIR/stdout | |
STDERR_FILE=$OUT_DIR/stderr | |
EXEC_TIME_FILE=$OUT_DIR/exec_time | |
EXIT_CODE_FILE=$OUT_DIR/exit_code | |
# placeholder, it will not be overwritten if process exits successfully | |
exit_code=0 | |
start_time=$(date +%s%03N) | |
# TODO: remove timeout usage. it comes with coreutils package | |
timeout --preserve-status --k=1s $TIMEOUT sh <<EOT || exit_code=$? | |
$@ 1> $STDOUT_FILE 2> $STDERR_FILE | |
EOT | |
end_time=$(date +%s%03N) | |
echo $start_time $end_time | |
echo $exit_code > $EXIT_CODE_FILE | |
echo $((end_time-start_time)) > $EXEC_TIME_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment