cleanup
This commit is contained in:
parent
f4c7335923
commit
5c42584931
@ -1,44 +1,46 @@
|
|||||||
function g_python {
|
function g_python {
|
||||||
|
|
||||||
g_rnd=$$
|
local g_python_tmp=${g_tmp}/$$
|
||||||
|
g_python_out=${g_python_tmp}/python-out
|
||||||
|
local g_python_in=${g_python_tmp}/python-in
|
||||||
|
local g_python_error=${g_python_tmp}/python-error
|
||||||
local g_python_jobs
|
local g_python_jobs
|
||||||
mapfile -t g_python_jobs < <(jobs -r)
|
mapfile -t g_python_jobs < <(jobs -r)
|
||||||
|
|
||||||
|
|
||||||
# Use python in backround for multiple python commands running much faster
|
# Use python in backround for multiple python commands running much faster
|
||||||
#if [ -z "${g_python_running}" ]
|
#if [ -z "${g_python_running}" ]
|
||||||
if [[ ${g_python_jobs[*]} != *python-pipeexec.py* ]]
|
if [[ ${g_python_jobs[*]} != *python-pipeexec.py* ]]
|
||||||
then
|
then
|
||||||
mkdir -p ${g_tmp}/${g_rnd}
|
mkdir -p ${g_python_tmp}
|
||||||
if [ -s ${g_tmp}/${g_rnd}/python-error ]
|
if [ -s ${g_python_error} ]
|
||||||
then
|
then
|
||||||
g_echo_error "From last python run: $(cat ${g_tmp}/${g_rnd}/python-error)"
|
g_echo_error "From last python run: $(cat ${g_python_error})"
|
||||||
fi
|
fi
|
||||||
[ -p ${g_tmp}/${g_rnd}/python-in ] || mkfifo ${g_tmp}/${g_rnd}/python-in
|
[ -p ${g_python_in} ] || mkfifo ${g_python_in}
|
||||||
#[ -p ${g_tmp}/${g_rnd}/python-out ] || mkfifo ${g_tmp}/${g_rnd}/python-out
|
|
||||||
echo "while 1:
|
echo "while 1:
|
||||||
exec(open(\"${g_tmp}/${g_rnd}/python-in\").read())
|
exec(open(\"${g_python_in}\").read())
|
||||||
print('DONE')
|
print('DONE')
|
||||||
" >${g_tmp}/${g_rnd}/python-pipeexec.py
|
" >${g_python_tmp}/python-pipeexec.py
|
||||||
|
|
||||||
# python stream channel
|
# 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 & }
|
{ python3 -u ${g_python_tmp}/python-pipeexec.py >>${g_python_out} 2>>${g_python_error} & }
|
||||||
g_python_running="true"
|
g_python_running="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do python
|
# do python
|
||||||
>${g_tmp}/${g_rnd}/python-out
|
>${g_python_out}
|
||||||
>${g_tmp}/${g_rnd}/python-error
|
>${g_python_error}
|
||||||
echo $@ >${g_tmp}/${g_rnd}/python-in
|
echo $@ >${g_python_in}
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
|
|
||||||
# Check for output
|
# Check for output
|
||||||
if [ -s ${g_tmp}/${g_rnd}/python-out ]
|
if [ -s ${g_python_out} ]
|
||||||
then
|
then
|
||||||
unset g_python_result
|
unset g_python_result
|
||||||
mapfile -t g_python_result <${g_tmp}/${g_rnd}/python-out
|
mapfile -t g_python_result <${g_python_out}
|
||||||
if [[ ${g_python_result[-1]} == DONE ]]
|
if [[ ${g_python_result[-1]} == DONE ]]
|
||||||
then
|
then
|
||||||
# remove the DONE output (last array element
|
# remove the DONE output (last array element
|
||||||
@ -49,10 +51,10 @@ function g_python {
|
|||||||
|
|
||||||
# Check for error
|
# Check for error
|
||||||
mapfile -t g_python_jobs < <(jobs -r)
|
mapfile -t g_python_jobs < <(jobs -r)
|
||||||
if [ -s "${g_tmp}/${g_rnd}/python-error" ] || [[ ${g_python_jobs[*]} != *python-pipeexec.py* ]]
|
if [ -s "${g_python_error}" ] || [[ ${g_python_jobs[*]} != *python-pipeexec.py* ]]
|
||||||
then
|
then
|
||||||
g_echo_error "Python Progress not running:
|
g_echo_error "Python Progress not running:
|
||||||
$(cat ${g_tmp}/${g_rnd}/python-error)"
|
$(cat ${g_python_error})"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user