python多线程处理重复任务10000次
2013-03-07 19:10
316 查看
#!/usr/bin/python import threading import urllib2 #f = open("/root/wget.txt","a") x = [ i.strip() for i in open("/root/ceshi/abc.txt","r") ] #f1 = open("/root/abc.txt","r") def wget(x): response = urllib2.urlopen("http://abc.abc.com/organize/domain/allupdate?domainname=%s"%x) if response.read() == '{"code": "0", "data": "ok"}': f.write('%s {"code": "0", "data": "ok"}\n'%x) else: f.write('%s {"code": "0", "data": "fail"}\n'%x) def main(): n = 0 while len(x) - n >= 20: f = open("/root/ceshi/wget.txt","a") threads = [] for i in range(n+0,n+20): t = threading.Thread(target=wget,args=(x[i],)) threads.append(t) for i in range(20): threads[i].start() for i in range(20): threads[i].join() n+=20 f.close() f = open("/root/ceshi/wget.txt","a") for i in range(n,len(x)): threads = [] t = threading.Thread(target=wget,args=(x[i])) threads.append(t) for i in range(len(x)-n): threads[i].start() for i in range(len(x)-n): threads[i].join() f.close() if __name__ == '__main__': main()
本文出自 “那些日子” 博客,请务必保留此出处http://tototo.blog.51cto.com/4567634/1149619
相关文章推荐
- python并行处理任务时 该用多进程?还是该用多线程?
- Python While循环语句 Python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务。其基本形式为: while 判断条件:
- python 多线程处理抓取网页
- PHP + PYTHON 多任务多线程,后台运行,计划任务-实现方法
- Python模块学习:threading 多线程控制和处理
- 解决SpringBoot项目使用多线程处理任务时无法通过@Autowired注入bean问题
- iOS开发—使用GCD实现多线程(单次或重复执行任务)
- Python - 时间处理与定时任务
- spring+ActiveMQ+JMS+线程池实现简单的分布式,多线程,多任务的异步任务处理系统
- 多节点服务器定时任务重复处理的问题
- 【原创】编写多线程Python爬虫来过滤八戒网上的发布任务
- c#(asp.net) 多线程示例,用于同时处理多个任务
- Python模块学习:threading 多线程控制和处理
- python 多线程处理实验
- Java多线程处理任务的封装
- python进阶之多线程对同一个全局变量的处理
- Spring-Boot中如何使用多线程处理任务
- 基于python多线程实现Linux任务并发执行
- Python 30 行代码实现小型多线程任务队列
- python threading 多线程控制和处理