better handling for python over bash

This commit is contained in:
olli 2024-03-25 16:48:19 +01:00
parent 6252eb4bb7
commit 39b3a944dd

View File

@ -13,22 +13,40 @@ function g_python {
exec(open(\"${g_tmp}/${g_rnd}/python-in\").read()) exec(open(\"${g_tmp}/${g_rnd}/python-in\").read())
" >${g_tmp}/${g_rnd}/python-pipeexec.py " >${g_tmp}/${g_rnd}/python-pipeexec.py
# bc stream channel # python stream channel
{ python3 -u ${g_tmp}/${g_rnd}/python-pipeexec.py >${g_tmp}/${g_rnd}/python-out 2>&1 & } { python3 -u ${g_tmp}/${g_rnd}/python-pipeexec.py >${g_tmp}/${g_rnd}/python-out 2>${g_tmp}/${g_rnd}/python-error & }
g_python_running="true" g_python_running="true"
fi fi
# do python # do python
echo "$@" >${g_tmp}/${g_rnd}/python-in &
sleep 0.02
local g_python_jobs local g_python_jobs
mapfile -t g_python_jobs < <(jobs -r) mapfile -t g_python_jobs < <(jobs -r)
if [[ $g_python_jobs =~ python-pipeexec.py ]] if ! [[ $g_python_jobs =~ python-pipeexec.py ]]
then then
echo $@ >${g_tmp}/${g_rnd}/python-in & g_echo_error "$(cat ${g_tmp}/${g_rnd}/python-error)"
read -t 0.1 g_python_result <${g_tmp}/${g_rnd}/python-out
echo "RESULT: $g_python_result"
else
echo "FAIL: $g_python_result"
unset g_python_running unset g_python_running
return 1
fi
if [ -n "$g_python_waitforoutput" ]
then
until [ -n "$g_python_result" ]
do
read -t 0.1 g_python_result <${g_tmp}/${g_rnd}/python-out
[ -s "${g_tmp}/${g_rnd}/python-error" ] && break
done
unset g_python_waitforoutput
else
read -t0.2 g_python_result <${g_tmp}/${g_rnd}/python-out
fi
if [ -s "${g_tmp}/${g_rnd}/python-error" ]
then
g_echo_error "$(cat ${g_tmp}/${g_rnd}/python-error)"
return 1
fi fi
} }