Compare commits

...

3 Commits

Author SHA1 Message Date
40e9624a98 run interactive python shell from bash 2024-03-24 11:38:16 +01:00
e0b15e0804 run interactive python shell from bash 2024-03-24 11:34:57 +01:00
796cd3e114 kill all background jobs 2024-03-24 11:33:20 +01:00
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,3 @@
functioon g_kill_all_background_jobs {
kill -9 $(jobs -p)
}

35
gaboshlib/g_python.sh Normal file
View File

@ -0,0 +1,35 @@
function g_python {
unset g_python_result
g_tmp=/tmp
g_rnd=$$
# Use python in backround for multiple python commands running much faster
if [ -z "${g_python_running}" ]
then
mkdir -p ${g_tmp}/${g_rnd}
[ -p ${g_tmp}/${g_rnd}/python-in ] || mkfifo ${g_tmp}/${g_rnd}/python-in
[ -p ${g_tmp}/${g_rnd}/python-out ] || mkfifo ${g_tmp}/${g_rnd}/python-out
echo "while 1:
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 & }
g_python_running="true"
fi
# do python
local g_python_jobs
mapfile -t g_python_jobs < <(jobs -r)
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"
unset g_python_running
fi
}