4

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.

2 Answers 2

4

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.

3

I think is much better to first understand how to think in a multithread way and its implications on the solution your need to create.

Generally, paradigms like Functional or Object Oriented introduce new ways to create solutions where each element of the software have different ways to interact. Concurrency is no different, when dealing with multiple process interacting you need to think about , for example , what happens when 2 processes need to read and write a global piece of data and so othe problems that appear in this kind paradigm.

Once your head adapted to the multiprocessing environment and learn the basic interactions between processes, then you may learn Python as a way to apply what you have learned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.