refactor: restrict console logging and pause during UI

This commit is contained in:
thePR0M3TH3AN committed 2025-08-22 22:24:04 -04:00
1 parent fde09bd1a0
commit 7b0344739f
4 files changed
+60 -9

No files matched your search

+23
View File
@@ -1,4 +1,6 @@
import logging
from contextlib import contextmanager
from functools import wraps
_console_paused = False
@@ -22,3 +24,24 @@ def resume_console_logging() -> None:
"""Resume logging to console handlers."""
global _console_paused
_console_paused = False
@contextmanager
def console_logging_paused() -> None:
"""Context manager to pause console logging within a block."""
pause_console_logging()
try:
yield
finally:
resume_console_logging()
def pause_logging_for_ui(func):
"""Decorator to pause console logging while ``func`` executes."""
@wraps(func)
def wrapper(*args, **kwargs):
with console_logging_paused():
return func(*args, **kwargs)
return wrapper