examples/advanced/multiprocess_load.py
import random
import multiprocessing
import time
import sys
# Works only in Python 3

c = 0

def f(n):
    global c
    i = 0
    while i < 40000000 / n:
        x = random.random()
        y = random.random()
        z = x + y
        i += 1
    return  z

if __name__ == '__main__':
    s = time.time()
    n = int(sys.argv[1])
    with multiprocessing.Pool(n) as p:
        dicts = p.map(f, [n]*n)
        print(dicts)
    print(time.time() - s)

examples/advanced/multiprocess_pool_async.py
#!/usr/bin/env python3
from multiprocessing import Pool
import os


def f(x):
    print("Input {} in process {}".format(x, os.getpid()))
    return x*x

def prt(z):
    print(z)

if __name__ == '__main__':
    with Pool(5) as p:
        results = p.imap(f, range(11)) # <multiprocessing.pool.IMapIterator object
        print(results)
        print('--')
        for r in results:
            print(r)

        #results = p.map_async(f, range(11))  # <multiprocessing.pool.MapResult object>, not iterable

        #results = []
        #p.map_async(f, range(11))  # <multiprocessing.pool.MapResult object>, not iterable
        #print(results)
        #for r in results:
        #    print(r)