The starmaps are awesome in the sense that they allow us to submit a list of tuples to a pool instead of your standard single variables. This, essentially, provides us slightly more flexibility, and can be very handy in certain situations.
In this example, we'll submit the list of tuples that each contain two distinct values--[(4,3),(2,1)]-- to our pool, and print the returned results:
from multiprocessing import Pool
import time
def myTask(x, y):
time.sleep(x/2)
return y*2
def main():
with Pool(4) as p:
print(p.starmap(myTask, [(4,3),(2,1)]))
if __name__ == '__main__':
main()
Notice that we've updated the myTask function in order to take in the same number of arguments as we have values in each of our tuples. We then sleep for x/2 seconds, and then return y squared.
This produces the following output:
$ python3.6 18_starmap.py
[6, 2]