【问题标题】:Can a Thread not be daemonized in python3.2?python3.2中可以不守护线程吗?
【发布时间】:2016-06-25 15:34:08
【问题描述】:

我在 Raspberry Pi 2 Model B

上运行 python-3.2 中的脚本

线程看起来像这样:

myThread = threading.Thread(target=someFunction, args=(arg1,arg2,arg3),
           daemon=True)
myThread.start()

每次调用此线程时。这个错误被触发:

TypeError: __init__() got an unexpected keyword argument 'daemon'

我知道 Debian Wheezy 版本 7.10 没有 Python-3.4 稳定版本,因此我必须使用 python 3.2

具有讽刺意味的是,Python 3.2 Documentation 确实声明 daemon 是一个可用的布尔值。

这是什么故障,我该如何解决?

【问题讨论】:

  • 该文档描述的是属性,而不是参数。只需在致电 start 之前分配给 daemon

标签: python multithreading python-3.2


【解决方案1】:

daemon 参数是在 3.3 版中添加的,see。在以前的版本中设置标志是这样的:

myThread = threading.Thread(target=someFunction, args=(arg1,arg2,arg3))
myThread.daemon = True
myThread.start()

【讨论】:

  • 这也适用于 python 3.4 吗?我只是对兼容性感到好奇,因为我的大部分代码都是基于 3.4
猜你喜欢
  • 2013-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多