John Gerwin De las Alas 2025-12-18 02:23:36 -05:00 committed by GitHub
commit 7e4cea36e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 0 deletions

View File

@ -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: