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-2025 CODEPRJ.COM