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


錯誤提示並且報pycharm異常退出

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以上的操作系統對多線程的限制

解決辦法

1、在終端運行代碼之前  export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES 臨時解決

2、  sudo echo "export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES" >> ~/.bash_profile && source ~/.bash_profile 長久解決

但是這個加上去之后我寫的flask接口會報錯,導入猴子包就ok

if __name__ == "__main__":
from gevent import monkey
monkey.patch_all()
app.run(debug=True, host='0.0.0.0', port=5000)

3、 打開pycharm

 

完美解決!!!!


免責聲明!

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



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