首页 > 编程语言 > 详细

python线程Example

时间:2014-05-26 07:25:16      阅读:445      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 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
bubuko.com,布布扣

 

python线程Example,布布扣,bubuko.com

python线程Example

原文:http://www.cnblogs.com/chuanheng/p/3747908.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!