一个一个下载 要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'

python多线程 批量下补丁的更多相关文章

  1. python多线程场景下print丢失

    python多线程情况下,print输出会出现丢失的情况,而logging模块的日志输出不会. 以下是示例代码,多运行几次就会发现这个有意思的现象 # coding:utf-8 import thre ...

  2. python多线程批量下载远程图片

    python多线程使用场景:多线程采集, 以及性能测试等 . 数据库驱动类-简单封装下 mysqlDriver.py #!/usr/bin/python3 #-*- coding: utf-8 -*- ...

  3. python 多线程批量传文件

    #!/usr/bin/env python #_*_ coding:utf-8 -*-#autho:leiyong#time:2017-06-05#version: 1.3 import parami ...

  4. Python多线程下的_strptime问题

    Python多线程下的_strptime问题 由于Python的datetime和time中的_strptime方法不支持多线程,运行时会报错: import datetimeimport threa ...

  5. python 多线程两种实现方式,Python多线程下的_strptime问题,

    python 多线程两种实现方式 原创 Linux操作系统 作者:杨奇龙 时间:2014-06-08 20:24:26  44021  0 目前python 提供了几种多线程实现方式 thread,t ...

  6. python多线程爬虫+批量下载斗图啦图片项目(关注、持续更新)

    python多线程爬虫项目() 爬取目标:斗图啦(起始url:http://www.doutula.com/photo/list/?page=1) 爬取内容:斗图啦全网图片 使用工具:requests ...

  7. Day9 - Python 多线程、进程

    Python之路,Day9, 进程.线程.协程篇   本节内容 操作系统发展史介绍 进程.与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\信号量 将线 ...

  8. Python多线程、进程、协程

    本节内容 操作系统发展史介绍 进程.与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\信号量 将线程变为守护进程 Event事件 queue队列 生产者 ...

  9. SAP下载报表速度慢?为啥你不试试python多线程

    由于SAP系统自身原因,或者公司内部ABAP代码的算法效率不高,我们经常遇到,手工执行某个事务代码下载某个报表会非常耗时,小爬曾见过公司某个自开发的报表,单家公司的数据下载超过半小时.如果我们刚好接到 ...

随机推荐

  1. win7 设置自动关机

    1.C:\Windows\System32\shutdown.exe 2. -s:表示关机: -r:表示重启: -t:表示时间,以秒为单位: -a:表示取消shutdown计划,即表示取消关机或重启命 ...

  2. GCC安装

    1.apt-get install gcc2.apt-get install make3.apt-get install gdb apt-get install build-essential  这个 ...

  3. [转]Form中控制Tab画布不同标签间切换的方法

    转自:http://yedward.net/?id=68 Form中一般常用的画布类型包括content.stacked.tab这三种,其实content类型的画布是每一个form都必须有的,而且只能 ...

  4. 发布GeoServer后预览提示下载wms文件

    这是因为发布的图层有中文所导致的,只需修改tomcat的server.xml文件 <Connector port="8080" protocol="HTTP/1.1 ...

  5. 移动端 touch 实现 拖动元素

    var homeMove = (function () { //touch自适应 var k = "ontouchend" in window ? "touchend&q ...

  6. YII中URL地址美化

    URL地址美化:urlManager地址管理(通过程序来实现url的地址美化) 例如: 原地址:http://localhost/项目/app/index.php?r=控制器/方法 新地址:http: ...

  7. Ajax返回数据类型

    MVC中,如果从controller返回的不是一个html,而是一个文本,使用AJAX中如何获取? 后台代码: public ActionResult UploadPicture() { return ...

  8. WPF-TxtBox控件利用KeyDown来控制键盘输入

    private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)        {            TextBox txt = ...

  9. mysql的分区技术

    一.概述 当 MySQL的总记录数超过了100万后,会出现性能的大幅度下降吗?答案是肯定的,但是,性 能下降>的比率不一而同,要看系统的架构.应用程序.还有>包括索引.服务器硬件等多种因素 ...

  10. xpath选择器

    一.xpath中节点关系 父(Parent):每个元素以及属性都有一个父 子(Children):元素节点可有零个.一个或多个子 同胞(Sibling):拥有相同的父的节点 先辈(Ancestor): ...