我喜欢将函数变成线程而不需要不必要的线来定义类的功能。我知道_thread,但看起来你不应该使用_thread。 python 3有没有相当于thread.start_new_thread的好习惯?Python中的thread.start_new_thread发生了什么3
12
A
回答
21
threading.Thread(target=some_callable_function).start()
,或者如果你想传递参数,
threading.Thread(target=some_callable_function,
args=(tuple, of, args),
kwargs={'dict': 'of', 'keyword': 'args'},
).start()
3
不幸的是,不是直接等同,因为Python 3意思是比Python 2更便携和_thread
接口被视为太为此目的的低级别。
在Python 3中,最佳做法通常是使用threading.Thread(target=f...)
。这使用不同的语义,但是首选,因为接口更容易移植到其他Python实现。
相关问题
- 1. Python 3中的types.ClassType发生了什么?
- 2. Rails 3中Builder :: XmlMarkup发生了什么?
- 3. Python 3.3中的Py_FlushLine发生了什么?
- 4. 在python中发生了什么b = a [:]?
- 5. Python的rect类发生了什么?
- 6. CGAL的python绑定发生了什么?
- 7. LocationResult中发生了什么?
- 8. DynamicViewDataDictionary.cs中发生了什么?
- 9. 发生了什么
- 10. )。发生了什么?
- 11. Python + JSON,None发生了什么?
- 12. Python-Regex,这里发生了什么?
- 13. 发生了什么错了?
- 14. CakePHP 3的控制器中的$ use属性发生了什么?
- 15. QB API V2和3中的报告发生了什么?
- 16. gxt 3.x中的BasePagingLoadResult发生了什么?
- 17. Xcode中的故事板发生了什么(swift 3)
- 18. 当我在迭代器上调用list()时,Python 3中发生了什么?
- 19. 在ExtJs 3中,发生afterrender事件后,组件发生了什么?
- 20. xUnit中的Assert.DoesNotThrowAsync()发生了什么?
- 21. 4.3中的Android Filterscript发生了什么?
- 22. ReactiveCocoa 5.0中的“startWith”发生了什么?
- 23. Jackson 1.9中的@JsonSerialize发生了什么?
- 24. Rails的application_record.rb中发生了什么?
- 25. Saxonica 9.7.0.4中的com.saxonica.ptree.StylesheetPackager发生了什么?
- 26. vs2005中的resharper发生了什么
- 27. WPF中的Control.InvokeRequired发生了什么?
- 28. ggplot2中我的geom_line()发生了什么?
- 29. XCode 4.2中的retainCount发生了什么?
- 30. qt4中的QListViewItem发生了什么?
我正在使用方法2将一个参数传递给线程,并且在*必须是序列之后得到错误:参数,而不是它。你知道这是什么意思吗? – lemiant 2011-06-12 00:17:44
确保你通过'(firstarg,)'而不是'(firstarg)' - 记住单元组元组需要将尾部逗号解释为元组。 – Amber 2011-06-12 00:29:20
可调用方法签名的外观如何?如果我使用类似'callable(** kwargs):'我得到'TypeError:callable()需要0位置参数,但1给出',如果我使用'callable(kwargs):'我得到'TypeError:callable )有一个意想不到的关键字参数'raw''。 – henrikstroem 2015-02-19 10:37:38