Spaces:
Sleeping
Sleeping
| # Run a pipeline command under a hard virtual-memory cap so a runaway job | |
| # dies with an allocation error instead of OOM-killing the whole VM. | |
| # | |
| # Usage: scripts/run_capped.sh [command...] | |
| # Env: ETYMOLOGY_MEMLIMIT_GIB (default 10). Set to 0 to disable ulimit. | |
| set -euo pipefail | |
| ROOT="$(cd "$(dirname "$0")/.." && pwd)" | |
| cd "$ROOT" | |
| export PYTHONPATH="${PYTHONPATH:-$ROOT}" | |
| export PATH="${HOME}/.local/bin:${PATH}" | |
| GIB="${ETYMOLOGY_MEMLIMIT_GIB:-10}" | |
| if [[ "$GIB" != "0" ]]; then | |
| # ulimit -v is in KiB on Linux. | |
| KB="$(python3 -c "print(int(float('${GIB}') * 1024 * 1024))")" | |
| ulimit -v "$KB" | |
| echo "run_capped: ulimit -v ${KB} KiB (${GIB} GiB)" >&2 | |
| fi | |
| if [[ $# -eq 0 ]]; then | |
| echo "usage: $0 command [args...]" >&2 | |
| exit 2 | |
| fi | |
| exec "$@" | |