Multiprocessing causes Python to crash and gives an error may have been in progress in another thread when fork() was called

前端 未结 2 1173
野的像风
野的像风 2020-12-04 09:21

I am relatively new to Python and trying to implement a Multiprocessing module for my for loop.

I have an array of Image url\'s stored in img_urls which I need to do

2条回答
  •  一向
    一向 (楼主)
    2020-12-04 10:22

    This error occurs because of added security to restrict multithreading in Mac OS High Sierra. I know this answer is a bit late, but I solved the problem using the following method:

    Set an environment variable .bash_profile to allow multithreading applications or scripts under the new Mac OS High Sierra security rules.

    Open a terminal:

    $ nano .bash_profile
    

    Add the following line to the end of the file:

    export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
    

    Save, exit, close terminal and re-open the terminal. Check to see that the environment variable is now set:

    $ env
    

    You will see output similar to:

    TERM_PROGRAM=Apple_Terminal
    SHELL=/bin/bash
    TERM=xterm-256color
    TMPDIR=/var/folders/pn/vasdlj3ojO#OOas4dasdffJq/T/
    Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.E7qLFJDSo/Render
    TERM_PROGRAM_VERSION=404
    TERM_SESSION_ID=NONE
    OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
    

    You should now be able to run your python script with multithreading.

提交回复
热议问题