python parallelism code example
Example 1: multiprocessing join python
from multiprocessing import Process
def say_hello(name='world'):
print "Hello, %s" % name
p = Process(target=say_hello)
p.start()
p.join() # Tells the program to wait until p has finished it's job before exiting
Example 2: worker pool model with multiprocessing
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))