Skip to content

Commit 9a2ddce

Browse files
authored
Merge pull request #2360 from danielaskdd/macos-gunicorn-numpy
Add macOS fork safety check for Gunicorn multi-worker mode
2 parents c6850ac + 4343db7 commit 9a2ddce

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lightrag/api/run_with_gunicorn.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ def main():
7676
print("=" * 80 + "\n")
7777
sys.exit(1)
7878

79+
# Check macOS fork safety environment variable for multi-worker mode
80+
if (
81+
platform.system() == "Darwin"
82+
and global_args.workers > 1
83+
and os.environ.get("OBJC_DISABLE_INITIALIZE_FORK_SAFETY") != "YES"
84+
):
85+
print("\n" + "=" * 80)
86+
print("❌ ERROR: Missing required environment variable on macOS!")
87+
print("=" * 80)
88+
print("\nmacOS with Gunicorn multi-worker mode requires:")
89+
print(" OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES")
90+
print("\nReason:")
91+
print(" NumPy uses macOS's Accelerate framework (Objective-C based) for")
92+
print(" vector computations. The Objective-C runtime has fork safety checks")
93+
print(" that will crash worker processes when embedding functions are called.")
94+
print("\nCurrent configuration:")
95+
print(" - Operating System: macOS (Darwin)")
96+
print(f" - Workers: {global_args.workers}")
97+
print(
98+
f" - Environment Variable: {os.environ.get('OBJC_DISABLE_INITIALIZE_FORK_SAFETY', 'NOT SET')}"
99+
)
100+
print("\nHow to fix:")
101+
print(" Option 1 - Set environment variable before starting (recommended):")
102+
print(" export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES")
103+
print(" lightrag-server")
104+
print("\n Option 2 - Add to your shell profile (~/.zshrc or ~/.bash_profile):")
105+
print(" echo 'export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES' >> ~/.zshrc")
106+
print(" source ~/.zshrc")
107+
print("\n Option 3 - Use single worker mode (no multiprocessing):")
108+
print(" lightrag-server --workers 1")
109+
print("=" * 80 + "\n")
110+
sys.exit(1)
111+
79112
# Check and install dependencies
80113
check_and_install_dependencies()
81114

0 commit comments

Comments
 (0)