Multiprocessing in Python: Pool

Multiprocessing in Python: Pool

LucidProgramming

5 лет назад

77,111 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Voice of Ash
Voice of Ash - 22.04.2023 16:16

Awesome video as usual!

Ответить
Novic Cen
Novic Cen - 14.09.2022 08:02

what about compared to threading?
which is faster and whats the difference

Ответить
Ninja HKZ
Ninja HKZ - 19.04.2022 01:13

thanks for the video bro, I was looking for several and several and could not understand as clearly as it was in this video!

Ответить
Summer XIA
Summer XIA - 15.02.2022 06:12

Thank you so much for your demonstration! Very clear and helpful. Can I ask why do we need the line "if _name_ == '__mian__' "? Thank you!

Ответить
buffaloofm
buffaloofm - 27.01.2022 16:00

I had problem with real time OCR and QR detection. when using single thread, it takes time save the images and process the OCR and QR which make the screen freeze about 0.3 seconds . so I used multiprocessing and make two process to capture images and process QR OCR and one shared list to put and read numpy arrays (ROI). It works better. Thank you very much.

Ответить
ighsight
ighsight - 12.11.2021 13:56

Excellent. I'm trying to implement this along with a timeout that will kill processes that are running longer than a set time. If anyone knows of a video that shows how to do that please pass it on.

Ответить
Sai Teja
Sai Teja - 08.11.2021 08:04

Awesome explanation!

Ответить
Utaya Surian
Utaya Surian - 04.08.2021 19:12

How to solve broken process pool on multiprocessing?

Ответить
Phillip Otey
Phillip Otey - 11.05.2021 00:42

Nice, one comment, you can use double the process of the number of cores so 16 cores is 32 process you can run.

Ответить
Mauricio CD
Mauricio CD - 19.02.2021 01:47

Hi! Is there anyway to use a multiprocessing within a function?

Specifically I'd like to know if for example it is possible to define a function "sum_square_with_mp(numbers)", where if a run the code, then I would be able to type sum_square_with_mp([1,3,5]) and get 1, 14 and 55.

Ответить
Dwi Agung Ahmad
Dwi Agung Ahmad - 21.12.2020 04:26

This work for py3 or no ???

Ответить
andrés recubenis sanchis
andrés recubenis sanchis - 16.10.2020 09:40

thank you!

Ответить
Paulo Sergio Schlogl
Paulo Sergio Schlogl - 29.09.2020 15:26

how can I use pool to count words in a huge file (genome = dna) to speed up my results.
for ex if I look for palindrome words in a text and need to make a dict (word:[list positions]) it takes a 2 minuts and I have 198000 text to look for. 8)
I was passing the arguments like alphabet = 'acgt' and k = integer representing the length of the words to look for.
i was using partial to pass the text to the function and then pool.apply_async(func, args). But still not good performance at all. do you have any suggestions?

Ответить
Chris Uhlik
Chris Uhlik - 09.06.2020 03:22

os.cpu_count() returns the number of virtual cores. On a 4-core, hyper-threading machine, it returns 8. However, python cannot efficiently run two interpreters on a single hyper-threaded core as the processes have separate memory spaces but the hyperthreaded core halves share a single memory space. To really operate at maximum efficiency, you should separate your code into a pool of 4 processes, each of which consisted of 2 threads running on a single interpreter. Thus the thread pairs could run concurrently taking advantage of overlapping IO and computation for example, while the 4 cores could each be doing some computationally intensive operation. Too much detail for this level of tutorial, but you might have significant savings for large memory processes by avoiding the default argument to Pool() and instead do Pool(os.cpu_count()/2) or Pool(psutil.cpu_count(logical = False))

Ответить
Tal Barak
Tal Barak - 16.05.2020 20:02

How the Pool object differs from ProcessPoolExecutor?

Ответить
Tal Barak
Tal Barak - 16.05.2020 18:07

It is work mentioning that it isn't possible to call p.join() before calling p.call(). At least it isn't possible, based on the official Python documentation.

Ответить
Sanjay Krish
Sanjay Krish - 14.05.2020 22:31

multiprocessing.cpu_count() finds the number of cores

Ответить
Manju M
Manju M - 12.05.2020 15:21

I would like to understand if my VM is having only 10 core, and if I allocate 200, what will happen and how does p.map( fun, [1....300]) , fucntion work if I'm calling function more than number core and args are more number of cores? thank you

Ответить
Aanchal Agarwal
Aanchal Agarwal - 06.04.2020 18:12

While using Multiprocessing Pool, I am getting a permission denied error. Can you help me with that

Ответить
Headphone
Headphone - 05.04.2020 15:31

How to explicitily limit the number of process , like I want to run only 3 process at a time .

Ответить
GameTester
GameTester - 01.04.2020 17:56

What should I do if my function needs two arguments? What would be the correct syntax? Should I create a list of two arguments on each element? result = p.map(function, (arg1,arg2)) ??

Ответить
rafael tsuha fachini
rafael tsuha fachini - 24.03.2020 19:32

great example and explanation bro!

Ответить
ASHKAN AJRIAN
ASHKAN AJRIAN - 08.03.2020 14:57

Great example! I have almost faced up with the same situation where I expected to speed up my execution time using Multiprocessing however I got longer run time! Thanks.

Ответить
Chris Maguire
Chris Maguire - 18.02.2020 20:19

great examplwe - thanks!

Ответить
Bal Mukund
Bal Mukund - 10.01.2020 14:38

well explained :)

Ответить
Ken Murphy
Ken Murphy - 02.01.2020 05:15

Fantastic Python class!

Ответить
NetworkStacks
NetworkStacks - 22.12.2019 12:01

Hi, I have code which interacts with network devices and takes some commands output from the devices and processes that output to take useful data and writes to a csv file. Now in the code i want to introduce multiprocessing but the problem is that the main() function calls the other functions and these functions also call other local functions as per requirement. Can you please help me out here as I am really confused on how to write the same code with multiprocessing because this operation is done on more than 100 devices and consumes about an hour to complete.

Ответить
googleuser
googleuser - 16.12.2019 09:08

Is it possible to map the function on gpu instead of cpu? Thank you very much for the tutorial.

Ответить
George Ford
George Ford - 15.12.2019 18:35

QUESTION: seeing how easy it is to use Pool, why would one choose to use multiprocessing.Process?

Ответить
Rohun Tripathi
Rohun Tripathi - 12.11.2019 10:19

Nice work!!

Ответить
theT00nL1nk
theT00nL1nk - 08.11.2019 05:13

Finally a clear tutorial on this! Was finally able to get it to work thanks to you.

Ответить
schogaia
schogaia - 27.09.2019 08:53

Excellent video, greetings from Germany

Ответить
KARAB1NAS
KARAB1NAS - 30.08.2019 00:20

cool video - what is the diffeerence with using 'Process' instead of ''Pool'?

Ответить
Francis Lapena
Francis Lapena - 13.08.2019 23:26

import multiprocessing as mp


mp.cpu_count()

Ответить
Linh Hoang
Linh Hoang - 12.08.2019 10:48

I like your vim setup. How can I get the style/customization like yours? Thanks.

Ответить
박동연
박동연 - 19.07.2019 04:04

Thanks for the great contents. I'm really learning a lot from these videos. I have a question, is there a smart way to give pool class multiple arguments? For example, in this video, function 'sum_square' takes 1 integer as an argument and to execute parallel computation we make a list of integers[numbers] and use 'p.map(sum_square, numbers)' . What I see is that the map function takes the function to parallelize and then a list of arguments. But for a function that takes multiple arguments other than only one, lets say for 2 integers, how do you design the pool multiprocessing?

Ответить
SDDA
SDDA - 17.07.2019 13:17

what is the terminal that you are using?

Ответить
Nathan Binks
Nathan Binks - 16.06.2019 19:26

I was using this code to understand what the code does and if it's converted into a exe on Windows, It'll eat all of your RAM in 1-5 seconds and create over 1000 processes with a system crash. (I saw the code create 5000+ at one time.)

Ответить
cavidan bagiri
cavidan bagiri - 30.05.2019 23:20

you are best teacher . Greetings from Azerbaijan

Ответить
marwan fouad
marwan fouad - 19.04.2019 00:20

Thanks a lot for this rich content, I really learned a lot from it. I have a question: What is the difference between Pooling and using the classical Process modules as in the previous videos?

Ответить
Francisco N
Francisco N - 17.01.2019 15:29

Nice work!! Thanks for this series of videos. Greetings from Chile

Ответить
Optisoins
Optisoins - 02.01.2019 00:32

Once again ! Very interesting video ! Thank you very much

Ответить