better handling for python over bash
This commit is contained in:
parent
6252eb4bb7
commit
39b3a944dd
@ -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"
|
||||
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
|
||||
echo "FAIL: $g_python_result"
|
||||
unset g_python_running
|
||||
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
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user