Member-only story

Why Ansible and Python fork break on macOS High Sierra+ and how to solve

How to avoid the fork fatal error using Ansible and Python

Luca Berton
3 min readNov 14, 2021
https://unsplash.com/photos/gvptKmonylk

Environment

macOS High Sierra+

Issue

objc[22868]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[22868]: +[__NSCFConstantString 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.

Resolution

  • current session only
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
  • for all future sessions
$ echo "OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES" >> .bash_profile

Save, exit, close terminal, and re-open the terminal. Verify with:

$ env
[...]
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

Root Cause

This error is caused by an added security to restrict multithreading in macOS High Sierra and later versions.

--

--

Luca Berton
Luca Berton

Written by Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday

No responses yet