You can refer to the below screenshot for the output. We can see the numbers are multplied with the function as the output. The pool.map() takes the function that we want to parallelize and an iterable as an argumentĮxample: from multiprocessing import Pool.Here, we are using the pool to increase the performance in the execution of the program.The numbers which are to multiply with the function are specified in the list as numbers=.The if _name_ = “_main_” is used to run the code directly when file is not imported.The function is defined as def num(n) then the function is returned as n*4.The pool module is used for the parallel execution of a function across multiple input values.In this example, I have imported a module called pool from multiprocessing. Now, we can see an example on multiprocessing pool class in python The different process running of the same python script Python Multiprocessing Pool Class Print("Cube: ".format(p2.is_alive()))Īs the execution is completed, we can see that process not alive so the false is returned as the output. The p1.start() function is used to start the process and call p1.join will terminate the process.The if _name_ = “_main_” is used to run the code directly when the file is not imported.The (num * num * num) is used to find the cube of the number.The function is defined as a def cube(num).The module multiprocessing is a package that supports the swapping process using an API.In this example, I have imported a module called multiprocessing.Here, we can see an example to find the cube of a number using multiprocessing in python The multiprocessing is a process in which two or more processors in computer simultaneously process two or more different portion of the same program. Python multiprocessing process class What is multiprocessing?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |