首页 > 解决方案 > Rails:调用 fork() 时可能正在另一个线程中进行

问题描述

升级到 OS10.14 后,调用时出现此错误Httparty

    response = HTTParty.get('http://api.stackexchange.com/2.2/questions?site=stackoverflow')
objc[4182]: +[__NSPlaceholderDictionary initialize] may have been in progress in another thread when fork() was called.
objc[4182]: +[__NSPlaceholderDictionary 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.

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES在启动 Rails 控制台之前,我已经尝试 过。

但它没有用。

标签: ruby-on-rails

解决方案


在 rails 控制台之前运行解决方法命令是不够的。

以下解决方案对我有用(遵循此说明):

如果遇到此错误,您可以将以下代码添加到位于主目录中的 .bash_profile 以解决此问题。

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
  1. 打开你的终端
  2. 通过键入 cd ~ 导航到您的主目录
  3. 在编辑器中打开 .bash_profile(VS Code 的代码,Atom 的 atom、vim、nano 等) nano .bash_profile
  4. 在您的文件中复制并粘贴 export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES (确保它位于文件底部的RVM 部分上方!)

* 这很重要 * 在我的 .bash_profile 中,它是这样的:

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM$

保存文件并退出所有编辑器和终端会话。重新打开你的编辑器,现在一切都应该正常工作了。

我在这个链接上找到了这个解决方案Kody Clemens Personal Blog


推荐阅读