This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1724|Reply: 0

[Solved] The "freeze_support()" line can be omitted if the program is not...

[Copy link]
Posted on 11/14/2024 1:12:46 PM | | |
PyTorch error: The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.

The error code is as follows:

RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable. RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

solution

Just put the code block you want to run into the main function and run it, for example:

distinguish

Code in modules (including function calls) without if __name__ == '__main__':: is also executed when imported.
Add if __name__ == '__main__':: Code in a module (including function calls) is executed only when the module is run as the main program, and not when imported.

This pattern helps improve code reusability and modularity, avoiding accidental execution of certain code when importing modules.




Previous:Windows PaddlePaddle installation tutorial
Next:Nvidia Related Software Download
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com