Python学习之(二) Python多线程学习

时间:2015-02-01 20:23:16   收藏:0   阅读:185

多线程的一个实例

#coding=utf-8
#!/usr/bin/python

import time  
import thread  
def timer(no, interval):  
    cnt = 0  
    while cnt<10: 
        time.sleep(interval)
        print ‘Thread:(%d) Time:%s‘ % (no, time.ctime())
        cnt+=1
    thread.exit_thread()  
     
   
def test(): #Use thread.start_new_thread() to create 2 new threads  
    thread.start_new_thread(timer, (1,2))  
    thread.start_new_thread(timer, (2,4))  
   
if __name__==‘__main__‘:  
    test() 

while 1:
    pass

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!