@@ -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 ("\n macOS with Gunicorn multi-worker mode requires:" )
89+ print (" OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES" )
90+ print ("\n Reason:" )
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 ("\n Current 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 ("\n How 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