鱼C论坛

 找回密码
 立即注册
查看: 2537|回复: 3

[已解决]关于threads多次开始的疑问

[复制链接]
发表于 2016-10-18 18:03:26 | 显示全部楼层
  1. while 1:
  2.     time.sleep(10)
  3.     for t in threads2:
  4.         print t.__dict__
  5.         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()类似
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-30 06:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表