python之multiprocessing(一)

[root@centos6 multiprocess]# cat multi_proc_pool.py
#!/usr/bin/env python
#encoding:utf8
import multiprocessing
import os,sys,time

result = []
def run(x,msg):
        print 'who-->I Love You __Forever 第%s次' %x,os.getpid(),msg
        time.sleep(2)  

        '''no more than --> timeout=5 or it will  raise exception:"TimeoutError"
        and do not execute next line...'''
        #print "Love ulimited..."

p = multiprocessing.Pool(processes=25)

for i in range(100):

        result.append(p.apply_async(run,('%s' %i,'iber')))

#p.apply_async(run,("iber",))
#p.apply_async(run,("yinting",)).get()
p.close()

for res in result:
        res.get(timeout=5)

当你的才华还撑不起你的野心时,就应该静下心来学习! Think big!Look forward!
原文地址:https://www.cnblogs.com/iber/p/7761555.html