#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:\Python27\Scripts>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]

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-01-19
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-01-06
  • 2022-01-05
相关资源
相似解决方案