3

Some python processes crash with:

objc[51435]: +[__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.

Those are processes using child shells, forking threads, etc. MacOS blocks them for some security reasons (which I am not sure what are, but that is what people say)

The solution is to disable this security check:

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

Which is fine for known libraries and dependencies, and within the currently running shell.

Is it safe to set it as a global environment variable, disabling this check globally in my local mac machine?

YFl
  • 845
  • 7
  • 22
  • 1
    I don't think this has anything to do with Python, per se. It's just incidental that you happen to be executing some program written in Objective C from a Python script. If it were me, I would only set that variable for the duration of the program which requires it. – chepner Sep 14 '22 at 19:09
  • so it has nothing to do with python? ahn.. do you know what this config really means? – YFl Sep 14 '22 at 19:51
  • As long as you are not calling fork(), it is safe but not advisable. – mohsyn Sep 15 '22 at 09:30
  • Thank you. I am not calling. A dependency (which I trust) is calling. Why is it not advisable? What does it do? – YFl Sep 15 '22 at 09:46

1 Answers1

4

Apple changed the way fork() behaves in High Sierra (>= 10.13).

If enabled, the OBJC_DISABLE_INITIALIZE_FORK_SAFETY variable turns off the immediate crash behaviour that their newer ObjectiveC framework otherwise enforces by default, as part of this change.

Your question "is it safe to set it as a global environment variable" depends on your definition of "safe" in this context.

It's safe in the sense your computer won't burst into flames.

It's unsafe in the sense it may mask crash information that would be otherwise presented by an app that goes awry, and may allow a fork-bomb type process to crash your computer.

So if you only have one use case where setting the flag is strictly necessary, then it's best to localise its setting to just that script/scenario.

kwiknik
  • 570
  • 3
  • 7