标签:python多线程
######################################
#!/usr/bin/env python
#encoding=utf-8
from multiprocessing import Process,Lock
import time,os
def say(i):
print ‘nihao:‘,i
#lock=Lock()
for n in range(101):
p=Process(target=say,args=(n,))
p.start()
#p.join()
########################################多线程池Pool,可限制多线程数量
#!/usr/bin/env python
#encoding=utf-8
import multiprocessing
import os,sys,time
result=[]
def run_cmd(i):
print ‘threading test:‘,i,os.getpid()
time.sleep(1.5)
p=multiprocessing.Pool(processs=25)
for n in range(100):
result.append(p.apply_async(run_cmd,(‘%s‘%n,)))
p.close()
#p.join()
for res in result:
res.get(timeout=5)
######################################
标签:python多线程
原文地址:http://qqran.blog.51cto.com/10014850/1962675