Skip to content

Commit 301bc51

Browse files
fix multiprocessing logging mess (#2025)
1 parent c8193f8 commit 301bc51

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

boxmot/utils/__init__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import Path
77

88
import numpy as np
9+
import multiprocessing as mp
910

1011
# global logger
1112
from loguru import logger
@@ -23,7 +24,17 @@
2324

2425
NUM_THREADS = min(8, max(1, os.cpu_count() - 1))
2526

26-
27-
def only_main_thread(record):
28-
# Check if the current thread is the main thread
29-
return threading.current_thread().name == "MainThread"
27+
def _is_main_process(record):
28+
return mp.current_process().name == "MainProcess"
29+
30+
def configure_logging():
31+
# this will remove *all* existing handlers and then add yours
32+
logger.configure(handlers=[
33+
{
34+
"sink": sys.stderr,
35+
"level": "INFO",
36+
"filter": _is_main_process,
37+
}
38+
])
39+
40+
configure_logging()

0 commit comments

Comments
 (0)