标签:os ar for sp on bs ef as python
ping多线程
#!/bin/env python2.7 import multiprocessing,subprocess import os,time result = [] #定义空列表 a=time.time() def run(i): IP=‘192.168.1.‘+str(i) #num = os.system(‘ping -c 1 -w 1 %s‘ % IP) num = subprocess.call(‘ping -c 1 -W 1 %s‘%IP , stdout = subprocess.PIPE, shell = True) if num == 0: print IP,‘is up !‘ else: #print IP,‘ is down !‘ pass p= multiprocessing.Pool(processes=45) for i in range(255): result.append(p.apply_async(run,(‘%s‘%i,))) p.close() #p.join() #安顺序执行类似for for res in result: #获取结果 res.get(timeout=2) print time.time()-a
标签:os ar for sp on bs ef as python
原文地址:http://my.oschina.net/jk409/blog/339840