[+] multiprocessing support

This commit is contained in:
Maxim Khomutov 2025-07-21 17:24:40 +03:00
parent e71d2f1a87
commit 1e4a7c23d1

View File

@ -1,4 +1,5 @@
import glob import glob
import multiprocessing
import os import os
import sys import sys
import threading import threading
@ -28,6 +29,8 @@ log_file = log_dir / "info.log"
os.makedirs(log_dir, exist_ok=True) os.makedirs(log_dir, exist_ok=True)
def zip_logs(): def zip_logs():
if multiprocessing.current_process().name != "MainProcess":
return
try: try:
if os.path.exists(log_file): if os.path.exists(log_file):
ftime = os.path.getmtime(log_file) ftime = os.path.getmtime(log_file)
@ -61,4 +64,7 @@ def setup(console_debug=False, file_debug=False, file_low_debug=False, module_se
logger.add(log_dir / "low_debug.log", level=0, rotation="10 MB") logger.add(log_dir / "low_debug.log", level=0, rotation="10 MB")
sys.excepthook = handle_exception sys.excepthook = handle_exception
threading.excepthook = handle_thread_exception threading.excepthook = handle_thread_exception
logger.bind(module="LoggerSetup", prefix="init").success("Logger initialized.") if multiprocessing.current_process().name != "MainProcess":
logger.bind(module="subproc", prefix="init").debug(f"Process id: {multiprocessing.current_process().pid} Started in {multiprocessing.current_process().name}")
else:
logger.bind(module="LoggerSetup", prefix="init").success("Logger initialized.")