From 4c6bbee8f9712e637567199e754dcde75793d1f1 Mon Sep 17 00:00:00 2001 From: John Gerwin De las Alas Date: Thu, 11 Dec 2025 18:28:02 +0800 Subject: [PATCH] fix(ml): disable Objective-C fork safety check on macOS On macOS, CoreML and other Objective-C frameworks are not fork-safe. When gunicorn forks workers, the Objective-C runtime may crash with: "NSPlaceholderString initialize may have been in progress in another thread when fork() was called." This sets OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES on macOS to allow CoreML execution provider to work properly with gunicorn workers. Closes #24493 --- machine-learning/immich_ml/gunicorn_conf.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/machine-learning/immich_ml/gunicorn_conf.py b/machine-learning/immich_ml/gunicorn_conf.py index efec3a95aa..bf75af4e62 100644 --- a/machine-learning/immich_ml/gunicorn_conf.py +++ b/machine-learning/immich_ml/gunicorn_conf.py @@ -1,4 +1,5 @@ import os +import sys from gunicorn.arbiter import Arbiter from gunicorn.workers.base import Worker @@ -6,6 +7,14 @@ from gunicorn.workers.base import Worker device_ids = os.environ.get("MACHINE_LEARNING_DEVICE_IDS", "0").replace(" ", "").split(",") env = os.environ +# On macOS, CoreML and other Objective-C frameworks are not fork-safe. +# When gunicorn forks workers, the Objective-C runtime may crash with: +# "NSPlaceholderString initialize may have been in progress in another thread when fork() was called" +# This environment variable disables the fork safety check to allow CoreML to work. +# See: https://github.com/immich-app/immich/issues/24493 +if sys.platform == "darwin": + env.setdefault("OBJC_DISABLE_INITIALIZE_FORK_SAFETY", "YES") + # Round-robin device assignment for each worker def pre_fork(arbiter: Arbiter, _: Worker) -> None: