Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1068712
  • 博文数量: 186
  • 博客积分: 4939
  • 博客等级: 上校
  • 技术积分: 2075
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 17:15
文章分类

全部博文(186)

文章存档

2018年(1)

2017年(3)

2016年(11)

2015年(42)

2014年(21)

2013年(9)

2012年(18)

2011年(46)

2010年(35)

分类: Python/Ruby

2011-06-28 17:15:57

  1. import threading,time

  2. class Demo(threading.Thread):
  3.    def __init__(self,color):
  4.      threading.Thread.__init__(self)

  5.      self.color=color

  6.    def run(self):

  7.     for i in xrange(3):

  8.      print "hello,world", i, self.isAlive(),self.color
  9.      time.sleep(1)

  10. list=[]

  11. for i in xrange(2):
  12.  test=Demo('green')
  13. #test.setDaemon(True)
  14.  test.start()
  15.  list.append(test)
  16.  for test in list:
  17.   test.join(15)

  18. print test.isAlive( ) #### it must be 'False' "
  19. print "main threading exit
test.setDaemon(True),主线程退出,子线程也随着退出。
阅读(1076) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~