hw23: Reading about multiprocessing vs threading
- Due before the beginning of class on Monday, March 25
Today’s homework is a reading on two approaches to concurrency in Python: multiprocessing (which should already be familiar to you from class already) and multithreading (which is a different concept we will talk about next).
After reading, fill in the short markdown file to confirm and check your understanding.
Reading
Because concurrency is not really well covered in our usual textbooks, you are going to read a blog post instead. I think the post actually does a terrific job of talking about these two approaches in the context of data scientist and hope you will enjoy it too!
Here it is: Multiprocessing vs Threading in Python by Sumit Ghosh.
Questions
Did you read the entire post?
(Answer yes or no)
Check out the following function. It uses a global variable to add to a running sum:
sum = 0 def addtosum(n): sum += n
What is the correct syntax to create a new thread to run this function with input n=25?
t1 = threading.Thread(addtosum, 25,)
t1 = threading.Thread(target=addtosum, args=(25,))
t1 = threading.Thread(target=addtosum(25),)
t1 = threading.Thread(target=addtosum)(25)
(Just enter the letter of the correct choice.)
The previous example function
addtosum
works with threading but not with multiprocessing. Why not?- GIL
- Race condition
- Shared memory
- Deadlock
- Akshually it does work
What is one thing in this reading that you’re still unsure/confused about and would like to discuss more in class?
Submit command
To submit files for this homework, run one of these commands:
submit -c=sd212 -p=hw23 hw23.md
club -csd212 -phw23 hw23.md
Download the file hw23.md to fill in and submit for this homework