Search code examples
ruby-on-rails

Rails: may have been in progress in another thread when fork() was called


After I upgrade to OS10.14, I got this error when I called 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.

I already tried export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES before I start rails console.

But it didn't work.


Solution

  • It is not enough running the workaround command before rails console.

    The following solution worked for me (follow this instructions):

    If you encounter this error, you can add the code below to your .bash_profile located in your home directory to fix the issue.

    export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
    
    1. Open your terminal
    2. Navigate to your home directory by typing cd ~
    3. Open .bash_profile in an editor (code for VS Code, atom for Atom, vim, nano, etc.) nano .bash_profile
    4. Copy and paste in export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES in your file (be sure it is above the RVM section at the bottom of the file!)

    * THIS IS IMPORTANT * In my case into .bash_profile it is something like this:

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

    Save the file and quit all editor and terminal sessions. Reopen your editor and everything should now work normally.

    I found this solution at this link Kody Clemens Personal Blog