sparkmicro / Ki-nTree

Fast part creation for KiCad and InvenTree
GNU General Public License v3.0
171 stars 31 forks source link

Multiprocessing crash on macOS #160

Closed 42CrMo4 closed 4 months ago

42CrMo4 commented 1 year ago

I tried to setup the new v1.0.1 (same with v1.0.0) on macOS and was not able to get a connection to inventree. The application is starting and everything was looking good. When I tried to connect to the Inventree instance (private and the public Demo) python crashes and no connection is established. The following Error Message is given in the Terminal:

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

After some googling I was able to find the following Stackoverflow question: https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr

For a workaround it is mentioned to use an environmental variable export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES to disable a security feature so that the multiprocessing does not lead to a crash. This works for me, but I do not think that this is good idea. As mentioned in the answer https://stackoverflow.com/a/69405247 there could be a solution but I do not know if this solution is possible for Ki-nTree.

with multiprocessing.get_context("spawn").Pool() as pool:
   pool.map(annotate,img_urls)

My Setup is: macOS Catalina 10.15.7 Intel Mac Python 3.9.16 Flet 0.5.2 Ki-nTree 1.0.1

If you need any other information, I'm happy to help and thank you for the excellent Tool.

eeintech commented 1 year ago

Hello @42CrMo4

Thank you for sharing your finding. It will be hard for me to reproduce your setup, I do not have access to any Macbook... If you would like to update the codebase and send a PR, it will be appreciated 👍

42CrMo4 commented 1 year ago

@eeintech I would love to but don't think I have the knowledge. Nevertheless I will give it a try.

eeintech commented 1 year ago

@42CrMo4 Happy to give you pointers if needed, sorry I can't help further 😕

EvilMustacheTwirl commented 10 months ago

This is because apple changed the way objectiveC handles multiprocessing you can solve it by doing the following in terminal:

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

source ~/.zshrc

Then it should start working again.

eeintech commented 4 months ago

Closing as won't be able to reproduce (don't have a macbook)