python多线程 批量下补丁
2014-05-03 14:18
274 查看
一个一个下载 要2个多小时。就直接起了个线程池。效果明显。 import urllib2 from urlparse import urlparse uri = 'http://******/patch****' d = urllib2.urlopen(uri) res = urlparse(uri) f = open('c:/' + res.path, 'wb') f.write(d.read()) f.close() print 'over' import urllib2 from urlparse import urlparse import Queue import threading mf = open('rest.txt', 'r') urls = [] while 1: line = mf.readline() if not line: break urls.append(line.replace('\r\n', '')) mf.close() queue = Queue.Queue() class ThreadUrl(threading.Thread): def __init__(self, queue, root): threading.Thread.__init__(self) self.queue = queue self.root = root def run(self): while True: uri = self.queue.get() print uri d = urllib2.urlopen(uri) res = urlparse(uri) f = open(self.root + res.path, 'wb') f.write(d.read()) f.close() self.queue.task_done() print 'task done' rootdir = 'C:/pathes/' for i in range(4): t = ThreadUrl(queue, rootdir) t.setDaemon(True) t.start() for uri in urls: queue.put(uri) queue.join() print 'over'
相关文章推荐
- 批量查询URL是否被收录(Python多线程)
- 多线程学习——python脚本批量修改华为交换机端口配置
- 用Python多线程和paramiko给主机组批量分发命令和传送文件
- python批量启动多线程
- Python多线程的threading Event
- python 多线程遍历windows盘符下文件操作
- Python实现批量读取word中表格信息的方法
- python批量给图加水印
- 如何使用Python批量修改文件中有规律的字符串
- python批量文件名修改的代码
- python执行多线程的实例
- python 多线程应用介绍
- Python多线程之线程池
- python基础之多线程锁机制
- python多线程使用thread
- Python 多线程 Condition 用法
- Python多线程
- Python GIL 多线程机制 (C source code)
- python 基于消息的多进程多线程程序
- python 批量重命名文件后缀