diff --git a/llama_stack/distribution/common.sh b/llama_stack/distribution/common.sh index 171023389..15220048b 100755 --- a/llama_stack/distribution/common.sh +++ b/llama_stack/distribution/common.sh @@ -10,12 +10,12 @@ cleanup() { set +x echo "Cleaning up..." conda deactivate - conda env remove --name $envname -y + conda env remove --name "$envname" -y } handle_int() { - if [ -n $ENVNAME ]; then - cleanup $ENVNAME + if [ -n "$ENVNAME" ]; then + cleanup "$ENVNAME" fi exit 1 } @@ -23,8 +23,8 @@ handle_int() { handle_exit() { if [ $? -ne 0 ]; then echo -e "\033[1;31mABORTING.\033[0m" - if [ -n $ENVNAME ]; then - cleanup $ENVNAME + if [ -n "$ENVNAME" ]; then + cleanup "$ENVNAME" fi fi } @@ -33,10 +33,14 @@ setup_cleanup_handlers() { trap handle_int INT trap handle_exit EXIT - __conda_setup="$('conda' 'shell.bash' 'hook' 2>/dev/null)" - eval "$__conda_setup" - - conda deactivate + if is_command_available conda; then + __conda_setup="$('conda' 'shell.bash' 'hook' 2>/dev/null)" + eval "$__conda_setup" + conda deactivate + else + echo "conda is not available" + exit 1 + fi } # check if a command is present diff --git a/llama_stack/distribution/utils/exec.py b/llama_stack/distribution/utils/exec.py index 63af35f84..4a3a95826 100644 --- a/llama_stack/distribution/utils/exec.py +++ b/llama_stack/distribution/utils/exec.py @@ -34,6 +34,7 @@ def _run_with_pty_unix(command): original_sigint = signal.getsignal(signal.SIGINT) ctrl_c_pressed = False + process = None def sigint_handler(signum, frame): nonlocal ctrl_c_pressed @@ -98,7 +99,7 @@ def _run_with_pty_unix(command): signal.signal(signal.SIGINT, original_sigint) os.close(master) - if process.poll() is None: + if process and process.poll() is None: process.terminate() process.wait()