python多线程

时间:2014-03-27 15:41:13   收藏:0   阅读:497
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import threading
import time
 
 
class Mythread(threading.Thread):
    def run(self):
        global num
        if mutex.acquire():
            num+=1
            print num
            mutex.release()
 
num=0
mutex=threading.Lock()
def test():
    for i in range(5):
        t=Mythread()
        t.start()
 
if __name__ == ‘__main__‘
    test()
     
‘‘‘
class mythread(threading.Thread):
    def __init__(self,num):
        threading.Thread.__init__(self)
        self.num=num
    def run(self):
        print self.num
 
for i in range(5):
    t=mythread(i)
    t.start()
#t=threading.Thread(target=run,args=(15,20))
#t.start()      
‘‘‘

  

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

原文:http://www.cnblogs.com/huangxiaohen/p/3627994.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!