错误提示并且报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__":<br /> from gevent import monkey<br /> monkey.patch_all()<br /> app.run(debug=True, host='0.0.0.0', port=5000)
3、 打开pycharm
![Mac上python多线程错误:...+[__NSPlaceholderDate initialize]... - 文章图片](/upload/getfiles/0001/2021/5/1/20210501121713811.jpg)
![Mac上python多线程错误:...+[__NSPlaceholderDate initialize]... - 文章图片](/upload/getfiles/0001/2021/5/1/20210501121714305.jpg)
![Mac上python多线程错误:...+[__NSPlaceholderDate initialize]... - 文章图片](/upload/getfiles/0001/2021/5/1/20210501121715234.jpg)
完美解决!!!!
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!