|
发表于 2016-10-18 18:03:26
|
显示全部楼层
- while 1:
- time.sleep(10)
- for t in threads2:
- print t.__dict__
- t.start()
复制代码
尝试打印t
会发现while 第一次进和第二次进入 threads2元素的值是不同的
第一次:
{'_Thread__ident': None, '_Thread__block': <Condition(<thread.lock object at 0x7f01140361f0>, 0)>, '_Thread__name': 'Thread-1', '_Thread__daemonic': False, '_Thread__started': <threading._Event object at 0x7f0113f29dd0>, '_Thread__stderr': <open file '<stderr>', mode 'w' at 0x7f01140851e0>, '_Thread__target': <function p at 0x7f0112072668>, '_Thread__kwargs': {}, '_Verbose__verbose': False, '_Thread__args': (0,), '_Thread__stopped': False, '_Thread__initialized': True}
第二次:
{'_Thread__ident': 139642559399680, '_Thread__block': <Condition(<thread.lock object at 0x7f01140361f0>, 0)>, '_Thread__name': 'Thread-1', '_Thread__daemonic': False, '_Thread__started': <threading._Event object at 0x7f0113f29dd0>, '_Thread__stderr': <open file '<stderr>', mode 'w' at 0x7f01140851e0>, '_Verbose__verbose': False, '_Thread__stopped': True, '_Thread__initialized': True}
所以把生成threads2变量的循环封装到一个函数里就好了 for t in get_threads()类似 |
|