首页 > 编程语言 > 详细

python多线程

时间:2014-03-27 15:41:13      阅读:493      评论:0      收藏:0      [点我收藏+]
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

python多线程

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

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