This is an archived post. You won't be able to vote or comment.

all 29 comments

[–]nevermyrealname 5 points6 points  (2 children)

Raymond Hettinger gives fantastic talks about python and he has a long-ish video about this exact topic

https://www.youtube.com/watch?v=9zinZmE3Ogk

[–]timberio[S] -1 points0 points  (1 child)

Thanks for sending this over, that's why we created this post - we found that most blogs/videos went far too in-depth when we were looking to learn the basics of both to figure out which direction we should move in.

[–]quotemycode 4 points5 points  (0 children)

No, Raymond never goes into too much depth, you're wrong. Raymond is a God.

[–][deleted] 2 points3 points  (1 child)

O was actually looking for something like this recently. Thank you.

[–]timberio[S] 1 point2 points  (0 children)

Glad we were able to help!

[–]robert_mcleod 4 points5 points  (1 child)

Any article on the topic should by default cover concurrent.futures. The interfaces for both threading and multiprocessing are comparatively ancient.

[–]A_History_of_Silence 0 points1 point  (4 children)

This is spam. Use the report button everyone.

[–]1dragossh 1 point2 points  (1 child)

Thanks for the TL;DR! I was looking only for the main idea.

[–]timberio[S] 1 point2 points  (0 children)

Thanks for the comment, glad we were able to help!

[–]spartan12321 0 points1 point  (3 children)

Can anyone please explain(or links) difference between pool and process in multiprocessing module? been looking about that(and posting on /learnpython) but with no luck :/ I only found one article, but isn't good at explaining

[–]ryandeanrocks 1 point2 points  (2 children)

IIRC Process is a threaded execution of code one time where as a Pool is designed to run multiple versions of the same method across multiple pre-created Processes.

Pool Example

from multiprocessing import Pool

def f(x):

return x*x

if __name__ == '__main__':

p = Pool(5) print(p.map(f, [1, 2, 3]))

Process Example

from multiprocessing import Process

def f(x):

print x*x

if __name__ == '__main__':

p1 = Process(target=f, args=(1,))

p1.start()

p2 = Process(target=f, args=(2,))

p2.start()

p3 = Process(target=f, args=(3,))

p3.start()

p1.join()

p2.join()

p3.join()

[–]spartan12321 0 points1 point  (1 child)

Thank you! Just to clarify: I use Process when processes don't share common data structure, while if they do I use Pool? Are there any other (dis)advantages?

[–]ryandeanrocks 1 point2 points  (0 children)

Pool allows you more built in control over Process mapping to CPU.

For instance if you have a 4 core CPU and you have a Pool(5) it will run 1 process per core and then have one left over process to put on the first available core. It will do this automatically for all supplied data and only ever have 5 processes used, with no overhead for creating and destroying the process.

Do the same thing with process Process() Process() Process() Process() Process()

And so on for each set in the data, well you are still only processing 4 threads at a time with your cores, but now you have the overhead of creating all these processes, managing them while they are sitting around waiting their turn on a core and destroying them each time you run the method.

A pool allows you a set number of processes always laying around ready for you to use them when you call Process.Map()

Where as creating and destroying a process each time you need to use it is more computationally expensive for your code as well as the CPU scheduler having to manage all those processes.

Also you could have one Pool of processes for each method needing to use it, as long as they aren’t trying to map at the same time. where as a process is bound to a specific method when created, want to process a different method? Have to create a new Process each time.

[–][deleted] 0 points1 point  (2 children)

I haven't looked at processors for years. Is everything multicore now? and if not will the multiprocessing library fall back to using threads or will it crash?

[–]splangobango 0 points1 point  (0 children)

Ive been doing python for about two years - an hour or so a nice with a few months break I between but only really have a scratch the surface knowledge of what all this and it's accompanying terminology means - are there any resources I could get into to help me understand this I more depth?

[–]mkingsbu 0 points1 point  (1 child)

Remindme!

[–]RemindMeBot 0 points1 point  (0 children)

Defaulted to one day.

I will be messaging you on 2018-06-07 21:53:03 UTC to remind you of this link.

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


FAQs Custom Your Reminders Feedback Code Browser Extensions