首页 > 代码库 > python线程Example
python线程Example
1 # -*- coding:utf-8 -*- 2 import time 3 import pymongo 4 from threading import Thread 5 from Queue import Queue 6 7 start = time.time() 8 9 f = open("ids.txt") 10 q = Queue() 11 12 def work(): 13 connection=pymongo.Connection(‘127.0.0.1‘,27017) 14 db = connection.pps_legual_cache 15 c = db.episode1 16 while 1: 17 line = q.get() 18 print c.find_one(int(line)) 19 q.task_done() 20 21 for i in range(5): 22 t = Thread(target=work) 23 t.setDaemon(True) 24 t.start() 25 26 27 for line in f.readlines(): 28 q.put(int(line)) 29 30 q.join() 31 32 end = time.time() 33 34 print end-start
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。