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

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

时间:2015-02-01 20:23:16      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

多线程的一个实例

#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

 

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

标签:

原文地址:http://www.cnblogs.com/lishuai0214/p/4265982.html

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