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
0:02 by talking about exchanging data.
0:04 So we've seen that we start the work
0:06 by saying pool.apply_async()
0:08 give it a function, and some arguments.
0:10 That's the first aspect of exchanging data
0:13 so we can pass in these arguments, 0 and 100
0:17 in this example.
0:18 And we're going to capture the results
0:20 and then after the work is done
0:22 after the pool's been joined and closed
0:24 and all that kind of stuff
0:25 we can go to the results and we can even check
0:27 if it were successful
0:28 and then we could call result.get
0:30 and that's going to give whatever the return value of
0:32 from do_math() work.
0:35 And those values that can be exchanged
0:37 they're pretty rich.
0:38 Basically, anything that can be pickled
0:40 which are most things, but not all things Python
0:43 those things can be created and passed in
0:45 or returned from these various functions.
0:48 So we're passing the arguments
0:50 we captured the results and hang onto it
0:53 and then when all the work is done
0:54 we just call get() to receive value from the function
0:57 that we ran in multiprocessing.