Compare commits

..

2 Commits

Author SHA1 Message Date
39b3a944dd better handling for python over bash 2024-03-25 16:48:19 +01:00
6252eb4bb7 output fix 2024-03-25 13:35:43 +01:00
2 changed files with 28 additions and 9 deletions

View File

@ -1,3 +1,4 @@
function g_kill_all_background_jobs {
kill -9 $(jobs -p)
kill -9 $(jobs -p) >/dev/null 2>&1
}

View File

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