python线程池实现多线程

参考文献

http://www.open-open.com/news/view/1c0179b

http://blog.jobbole.com/52060/

按照这个博客,实现获取多台服务器的空间使用情况

代码如下:

python线程池实现多线程
#!/usr/bin/env python2.7
#-*- coding:utf-8 -*-

from multiprocessing.dummy import Pool as ThreadPool
import subprocess
import time

results = []
ip_list = [ip.strip() for ip in open(./ssd,r)]

def getsize(host):
        now = time.strftime(%Y-%m-%d %H:%M:%S,time.localtime(time.time()))
        print host,now
        command = "df -h"
        sys_cmd = """ssh -n -f -i /usr/home/guosong/.ssh/id_rsa -p 26387 -o StrictHostKeyChecking=no -o ConnectTimeout=2 root@‘%s‘ \"%s\" """ %(host,command)

        pipe = subprocess.Popen(sys_cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,stdin=subprocess.PIPE)
        stdout,stderr = pipe.communicate()
        #print stdout

        results.append(stdout)

pool = ThreadPool(4)

pool.map(getsize,ip_list)
pool.close()

pool.join()
python线程池实现多线程

python线程池实现多线程,布布扣,bubuko.com

python线程池实现多线程

上一篇:python相关资料


下一篇:Kubernetes初露锋芒(Pod详解)