Skip to content

Instantly share code, notes, and snippets.

@chr5tphr
Created July 30, 2020 20:03
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 chr5tphr/c1a5c444533bdfc3b2c40622a875a12e to your computer and use it in GitHub Desktop.
Save chr5tphr/c1a5c444533bdfc3b2c40622a875a12e to your computer and use it in GitHub Desktop.
Require/ install python virtual environment with flock to support concurrent calls.
#!/usr/bin/env bash
RETVAL=0
VENV="${1:?"No path to virtual environment supplied!"}"
shift
exec 3>"${VENV}.lock"
if flock --exclusive --wait 180 3; then
if ! [ -d "$VENV" ]; then
virtualenv -p python3 "$VENV" && "${VENV}/bin/pip" install "$@"
fi
else
echo "Could not acquire lock!" >&2
RETVAL=1
fi
exec 3>&-
exit "$RETVAL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment