refactor: centralize ProcessPoolExecutor worker count calculation to a shared module-level variable

This commit is contained in:
g0ldyy
2026-01-04 23:48:33 +01:00
parent 7e98d1f067
commit a722081975
2 changed files with 6 additions and 12 deletions
+4 -6
View File
@@ -13,6 +13,10 @@ except ValueError:
_mp_context = multiprocessing.get_context("spawn")
app_executor = None
max_workers = settings.EXECUTOR_MAX_WORKERS
if max_workers is None:
cpu_count = os.cpu_count() or 1
max_workers = min(cpu_count, 4)
def worker_initializer():
@@ -22,12 +26,6 @@ def worker_initializer():
def setup_executor():
global app_executor
max_workers = settings.EXECUTOR_MAX_WORKERS
if max_workers is None:
cpu_count = os.cpu_count() or 1
max_workers = min(cpu_count, 4)
app_executor = ProcessPoolExecutor(
max_workers=max_workers, mp_context=_mp_context, initializer=worker_initializer
)
+2 -6
View File
@@ -1,11 +1,11 @@
import logging
import os
import re
import sys
import time
from loguru import logger
from comet.core.execution import max_workers
from comet.core.log_levels import (CUSTOM_LOG_LEVELS, STANDARD_LOG_LEVELS,
get_level_info)
@@ -177,13 +177,9 @@ def log_startup_info(settings):
)
logger.log("COMET", f"Gunicorn Preload App: {settings.GUNICORN_PRELOAD_APP}")
executor_workers = settings.EXECUTOR_MAX_WORKERS
if executor_workers is None:
cpu_count = os.cpu_count() or 1
executor_workers = min(cpu_count, 4)
logger.log(
"COMET",
f"ProcessPoolExecutor: {executor_workers} workers {'(auto)' if settings.EXECUTOR_MAX_WORKERS is None else ''}",
f"ProcessPoolExecutor: {max_workers} workers {'(auto)' if settings.EXECUTOR_MAX_WORKERS is None else ''}",
)
if settings.PUBLIC_BASE_URL: