Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objc[54401]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. #1418

Closed
dmd opened this issue Feb 18, 2021 · 9 comments

Comments

@dmd
Copy link

dmd commented Feb 18, 2021

Putting this here so anyone else using rq with requests can find it.

On a brand new install of rq, e.g., create a new python3.9 virtualenv and pip install rq:

❯ python
Python 3.9.1 (default, Feb  3 2021, 07:38:02)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from redis import Redis
>>> from rq import Queue
>>> q = Queue(connection=Redis())
>>> import requests
>>> q.enqueue(requests.get, 'http://example.com')
Job('2aa722f8-c408-4dfa-a74d-fe0b2934fced', enqueued_at=datetime.datetime(2021, 2, 18, 17, 30, 4, 443845))
>>>

Then,

❯ rq worker
12:36:37 Worker rq:worker:9375eef5aeb14c0da30782a71f48ff23: started, version 1.7.0
12:36:37 Subscribing to channel rq:pubsub:9375eef5aeb14c0da30782a71f48ff23
12:36:37 *** Listening on default...
12:36:37 default: requests.api.get('http://3e.org') (d334dc61-7ec3-4287-acd0-deea546be9ba)
objc[54724]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[54724]: +[__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.
12:36:38 Moving job to FailedJobRegistry (work-horse terminated unexpectedly; waitpid returned 6)

The solution is:

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
rq worker
@dmd dmd closed this as completed Feb 18, 2021
@manmat
Copy link

manmat commented Oct 12, 2021

This helped me solve the same error when using functions_framework to test Google Cloud Functions locally. Many thanks

@amotl
Copy link

amotl commented Nov 6, 2021

Dear Daniel,

thanks a stack, this saved my day when I was trying to invoke a worker function using Python's multiprocessing module.

With kind regards,
Andreas.

@supermandavid
Copy link

I have been searching every where for this

you are God send.

@asennoussi
Copy link

This doesn't seem to work under Monterey anymore.
Any idea how to solve it?

@stevenhaley
Copy link

This doesn't seem to work under Monterey anymore. Any idea how to solve it?

@Sshuichi: I'm using Monterey (12.3 21E230) and it still worked for me. 🎉 Unfortunately that probably means you've got a different issue to resolve.

@kernelguardian
Copy link

For anyone wondering why this works
Apple changed macOS fork() behaviour since High Sierra. The OBJC_DISABLE_INITIALIZE_FORK_SAFETY=yes variable turns off the immediate crash behaviour that their newer ObjectiveC framework usually enforces now by default. This can affect any language that is doing multithreading / multiprocessing using fork() on macOS >= 10.13, especially when "native extensions" / C code extensions are used.

Reference
StackOverflow Link

@odoublewen
Copy link

A relevant blog post that also suggests the same fix:
https://hynek.me/til/rq-macos/

The author includes this warning:

Be aware that this is akin to taking the batteries out of your smoke detector to stop the annoying beeping. fork() should only be used if you immediately exec() afterwards – if at all.

@mambajoe
Copy link

thanks for that info, it saved my day... was blocked for that error

@PranjalAgni
Copy link

Finally it got solved, that one export line took 1 day for me but now its fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants