Async Techniques and Examples in Python Transcripts
Chapter: Leveraging CPU cores with multiprocessing
Lecture: Concept: Return values
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Let's wrap up this chapter on multiprocessing by talking about exchanging data. So we've seen that we start the work by saying pool.apply_async()
0:09
give it a function, and some arguments. That's the first aspect of exchanging data so we can pass in these arguments, 0 and 100 in this example.
0:19
And we're going to capture the results and then after the work is done after the pool's been joined and closed and all that kind of stuff
0:26
we can go to the results and we can even check if it were successful and then we could call result.get
0:31
and that's going to give whatever the return value of from do_math() work. And those values that can be exchanged they're pretty rich.
0:39
Basically, anything that can be pickled which are most things, but not all things Python those things can be created and passed in
0:46
or returned from these various functions. So we're passing the arguments we captured the results and hang onto it and then when all the work is done
0:55
we just call get() to receive value from the function that we ran in multiprocessing.