Skip to content

Instantly share code, notes, and snippets.

@Fogapod
Created October 21, 2019 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fogapod/7b55095c3b5968a480224acb31946999 to your computer and use it in GitHub Desktop.
Save Fogapod/7b55095c3b5968a480224acb31946999 to your computer and use it in GitHub Desktop.
import time
for i in range(5):
time.sleep(1)
print(i)
#!/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