Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiprocessing.freeze_support()

Why does the multiprocessing module need to call a specific function to work when being "frozen" to produce a windows executable?

like image 634
Voo Avatar asked Dec 17 '12 21:12

Voo


People also ask

What does multiprocessing Freeze_support () do?

freeze_support() function. Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable. (Has been tested with py2exe, PyInstaller and cx_Freeze.) This function will allow a frozen program to create and start new processes via the multiprocessing.

What is multiprocessing in Python?

Multiprocessing in Python is a built-in package that allows the system to run multiple processes simultaneously. It will enable the breaking of applications into smaller threads that can run independently.

How does multiprocessing pool work?

It works like a map-reduce architecture. It maps the input to the different processors and collects the output from all the processors. After the execution of code, it returns the output in form of a list or array. It waits for all the tasks to finish and then returns the output.

What is pool in multiprocessing Python?

The Pool class in multiprocessing can handle an enormous number of processes. It allows you to run multiple jobs per process (due to its ability to queue the jobs). The memory is allocated only to the executing processes, unlike the Process class, which allocates memory to all the processes.


1 Answers

The reason is lack of fork() on Windows (which is not entirely true). Because of this, on Windows the fork is simulated by creating a new process in which code, which on Linux is being run in child process, is being run. As the code is to be run in technically unrelated process, it has to be delivered there before it can be run. The way it's being delivered is first it's being pickled and then sent through the pipe from the original process to the new one. In addition this new process is being informed it has to run the code passed by pipe, by passing --multiprocessing-fork command line argument to it. If you take a look at implementation of freeze_support() function its task is to check if the process it's being run in is supposed to run code passed by pipe or not.

like image 108
Piotr Dobrogost Avatar answered Oct 03 '22 07:10

Piotr Dobrogost