Additional sensors error checking

pull/153/head
aristocratos 2020-06-21 13:39:47 +02:00
parent 67e358c43e
commit b38ada1762
2 changed files with 23 additions and 11 deletions

31
bashtop
View File

@ -1368,10 +1368,10 @@ create_graph() { #? Create a graph from an array of percentage values, usage;
#* Create graph by walking through all values for each line, speed up by counting similar values and print once, when difference is met #* Create graph by walking through all values for each line, speed up by counting similar values and print once, when difference is met
while ((x<value_width)); do while ((x<value_width)); do
if [[ -z ${input_array[x]} ]]; then input_array[x]=0; fi if [[ -z ${input_array[x]} ]] || ((input_array[x]<1)); then input_array[x]=0; fi
#* Print empty space if current value is less than percentage for current line #* Print empty space if current value is less than percentage for current line
while ((x<value_width & input_array[offset+x]*virt_height/100<next_value)); do while ((x<value_width & input_array[x]*virt_height/100<next_value)); do
((++count)) ((++count))
((++x)) ((++x))
done done
@ -2091,14 +2091,18 @@ collect_cpu_temps() { #? Collect cpu temperatures
#* Fetch output from "sensors" command or psutil to a variable #* Fetch output from "sensors" command or psutil to a variable
if [[ $sensor_comm == "psutil" ]]; then if [[ $sensor_comm == "psutil" ]]; then
py_command -vn sens_var "get_sensors()" if ! py_command -vn sens_var "get_sensors()"; then
elif [[ $sensor_comm == "sensors" ]]; then if command -v sensors >/dev/null 2>&1; then sensor_comm="sensors"
else sensor_comm=""; check_temp="false"; resized=1; return; fi
fi
fi
if [[ $sensor_comm == "sensors" ]]; then
if [[ $use_psutil == true ]]; then if [[ $use_psutil == true ]]; then
py_command -vn sens_var "get_cmd_out('sensors 2>/dev/null')" py_command -vn sens_var "get_cmd_out('sensors 2>/dev/null')"
else else
read -rd '' sens_var < <(sensors 2>/dev/null || true) || true read -rd '' sens_var < <(sensors 2>/dev/null || true) || true
fi fi
elif [[ $sensor_comm != "sensors" ]]; then elif [[ $sensor_comm != "sensors" && $sensor_comm != "psutil" ]]; then
if [[ $use_psutil == true ]]; then if [[ $use_psutil == true ]]; then
py_command -v misc_var "get_cmd_out('${sensor_comm} measure_temp 2>/dev/null')" py_command -v misc_var "get_cmd_out('${sensor_comm} measure_temp 2>/dev/null')"
else else
@ -5201,9 +5205,8 @@ while command != 'quit':
exec(command) exec(command)
except Exception as e: except Exception as e:
pass pass
print('/ERROR') print('\n', '/ERROR')
print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr) print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr)
quit()
else: else:
continue continue
print('/EOL') print('/EOL')
@ -5251,7 +5254,7 @@ fi
#* Start infinite loop #* Start infinite loop
until false; do until false; do
if [[ $use_psutil == true ]] && [[ -n $failed_pipe || -n $py_error ]]; then if [[ $use_psutil == true ]] && [[ -n $failed_pipe ]]; then
if ((++failed_pipes>10)); then if ((++failed_pipes>10)); then
if [[ $system == "Linux" ]]; then if [[ $system == "Linux" ]]; then
use_psutil="false" use_psutil="false"
@ -5261,7 +5264,17 @@ until false; do
fi fi
coproc pycoproc (python3 ${pywrapper}) coproc pycoproc (python3 ${pywrapper})
sleep 0.1 sleep 0.1
unset failed_pipe py_error unset failed_pipe
fi
if [[ -n $py_error ]]; then
if ((++py_errors>10)); then
if [[ $system == "Linux" ]]; then
use_psutil="false"
else
quit_ 1
fi
fi
unset py_error
fi fi
main_loop main_loop
done done

3
src/bashtop.psutil.py Normal file → Executable file
View File

@ -388,9 +388,8 @@ while command != 'quit':
exec(command) exec(command)
except Exception as e: except Exception as e:
pass pass
print('/ERROR') print('\n', '/ERROR')
print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr) print(f'PSUTIL ERROR! Command: {command}\n{e}', file=sys.stderr)
quit()
else: else:
continue continue
print('/EOL') print('/EOL')