码迷,mamicode.com
首页 > 编程语言 > 详细

python线程Example

时间:2014-05-26 07:25:25      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:style   class   c   blog   code   java   

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

标签:style   class   c   blog   code   java   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!