首页 > 编程语言 > 详细

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

时间:2015-02-01 20:21:50      阅读:328      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!