[Python] Using multiprocessing to package multiple processes into exe, the solution to the problem of full memory when executing the exe

Solution to the problem that the memory is full when Python multi-threaded packaged exe is executed


Preface

The multiprocessing module is used in the Python script. When it is packaged into an exe and executed, the memory will quickly fill up, and the computer will have to be restarted. Because many libraries are used in the script, I thought it was a problem with other libraries. I changed some contents of the script, but repackaging still doesn't work. Later, I thought it was a problem with the packaging tool, and it still didn't work after changing the packaging tool.
Don't talk nonsense, use the multiprocessing library, directly add multiprocessing.freeze_support() in the first line of if name == ' main ':, repackage and the exe can be executed 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 a python script, packaging the script into an exe and then executing the exe causes the memory to become 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 it to execute the exe file normally.

Guess you like

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