Added some safety checks and forced C locale for console printing

This commit is contained in:
Félix Boisselier
2023-10-27 14:44:06 +02:00
parent c102d4145c
commit a03a3c2e4b
4 changed files with 72 additions and 19 deletions

View File

@@ -35,10 +35,6 @@ import locale
from datetime import datetime
matplotlib.use('Agg')
try:
locale.setlocale(locale.LC_TIME, locale.getdefaultlocale())
except locale.Error:
locale.setlocale(locale.LC_TIME, 'C')
PEAKS_DETECTION_THRESHOLD = 0.05
@@ -52,6 +48,22 @@ KLIPPAIN_COLORS = {
}
# Set the best locale for time and date formating (generation of the titles)
try:
locale.setlocale(locale.LC_TIME, locale.getdefaultlocale())
except locale.Error:
locale.setlocale(locale.LC_TIME, 'C')
# Override the built-in print function to avoid problem in Klipper due to locale settings
original_print = print
def print_with_c_locale(*args, **kwargs):
original_locale = locale.setlocale(locale.LC_ALL, None)
locale.setlocale(locale.LC_ALL, 'C')
original_print(*args, **kwargs)
locale.setlocale(locale.LC_ALL, original_locale)
print = print_with_c_locale
######################################################################
# Computation
######################################################################