From f30d8e517a64abe1673c202bf2d9facf4dde8423 Mon Sep 17 00:00:00 2001 From: zehkira <9485872-zehkira@users.noreply.gitlab.com> Date: Fri, 14 Nov 2025 10:32:22 +0100 Subject: [PATCH] Use threading.Lock instead of GLib.idle_add in logging --- source/monophony/logging.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/source/monophony/logging.py b/source/monophony/logging.py index 78451e1..8b3acdf 100644 --- a/source/monophony/logging.py +++ b/source/monophony/logging.py @@ -8,11 +8,10 @@ from typing import Any from monophony import NAME, __version__ -from gi.repository import GLib - _LOG_LEVELS_VARIABLE = 'MONOPHONY_LOG_LEVELS' _DEFAULT_LOG_LEVELS = 'INFO,WARN,ERRO' +_lock = threading.Lock() class LogLevel: @@ -67,9 +66,7 @@ def _log(level: type, source: str, text: str, details: str): if level.name not in log_levels: return - if threading.current_thread() is not threading.main_thread(): - GLib.idle_add(_log, level, source, text, details) - return + _lock.acquire() text = text.strip() details = details.strip() @@ -93,6 +90,8 @@ def _log(level: type, source: str, text: str, details: str): f'{traceback.format_exc()}\n' ) + _lock.release() + def _get_directory() -> str: return os.getenv('XDG_RUNTIME_DIR', '/var/tmp') + '/' + NAME -- GitLab