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

多线程的一个实例

#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

 

posted @ 2015-02-01 19:37  lishuai0214  阅读(187)  评论(0编辑  收藏  举报