#coding=utf-8
import multiprocessing
import os
import time
import random
def m1(x):
time.sleep(random.random()*4)
print "pid:",os.getpid(),x*x
return x*x
if __name__=='__main__':
pool=multiprocessing.Pool(multiprocessing.cpu_count())
iList=range(8)
print pool.map(m1,iList)
c:Python27Scripts>python task_test.py
pid: 19156 4
pid: 9544 0
pid: 9544 25
pid: 9544 36
pid: 13616 1
pid: 15892 9
pid: 19156 16
pid: 9544 49
[0, 1, 4, 9, 16, 25, 36, 49]