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

 

完美解决!!!!

posted @ 2020-11-25 17:55  Mr·Li程序员  阅读(1404)  评论(0编辑  收藏  举报