[Python] Use multiprocessing and multi-threading to package into exe, and the solution to the full memory when executing exe

The solution to the full memory when Python multi-threaded packaging exe is executed


foreword

The multiprocessing multi-process module is used in the Python script. When it is packaged into an exe for execution, the memory will be full quickly, and the computer has to be restarted at this time. Because a lot of libraries are used in the script, I thought it was a problem with other libraries. I changed the content of the script, but repackaging still doesn't work. Later, I thought it was a problem with the packaging tool, but it still didn't work after changing the packaging tool.
Nonsense, use the multiprocessing library, directly add multiprocessing.freeze_support() in the first line of if name == ' main ':, and repackage it to execute the exe normally.
The code is as follows (example):

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

Summarize

This article mainly introduces the problem that after using multiprocessing in the python script, the script is packaged into an exe and then executed, causing the memory to be full and unable to run normally. The solution is to add multiprocessing.freeze_support() in the first line of if name == ' main ':, and then repackage to execute the exe file normally.

Guess you like

Origin blog.csdn.net/liaotianyin/article/details/130864125