Python threading vs. multiprocessing: Should I learn one before the other

concurrencypython

I'm looking to dive into multithreading or multiprocessing in Python. Question: should I be learning one before the other (for any reason)? If so, which one and why?

I've read the pro's and con's in SO questions like this, but I'm not really sure how they relate to the pedagogical value of learning one or the other first.

Best Answer

When you are starting out, it doesn't matter which one you choose. What is more important is getting a better understanding of how to parallelize work. If you don't have that base understanding, you will not be able to take advantage of the fine point that differentiate between the two.

Pick one and get used to thinking about what work can be done in parallel. Think about ways you can break a large task into smaller pieces. Think about what pieces of memory all the tasks need access to and if that value ever changes. Think about if it is ok if each task had it's own local value to change and if combining all of the local values at the end could prevent contention.

Once you think you have a handle on those types of things, than you can come back and look at the differences again. With a stronger understanding of concurrency, you will have better understanding of how the two methods differ.

Related Topic