錯誤提示
objc[27880]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called.
objc[27880]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
錯誤原因
剛開始以為是代碼的問題,后來才發現其實是macOS的High Sierra以上的操作系統對多線程的限制。
解決辦法
在環境變量中添加export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
- 終端
// 零時解決方法
// 在終端中執行以下命令,接着繼續執行python程序
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
// 永久解決方案
// 終端中執行以下命令
sudo echo "export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES" >> ~/.bash_profile && source ~/.bash_profile
- PyCharm
// 在下面的選擇中添加`OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES`,重啟`PyCharm`即可
Run -> Edit Configuations... -> Environment variables


