Mac上python多線程錯誤:...+[__NSPlaceholderDate initialize]...


錯誤提示

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  



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM