加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 建站 > 正文

一篇文章读懂 Python 多线程

发布时间:2019-09-25 01:31:04 所属栏目:建站 来源:编程派
导读:Threading模块从 Python 1.5.2 版开始呈现,用于加强底层的多线程模块thread。Threading 模块让操纵多线程变得更简朴,而且支持措施同时运行多个操纵。 留意,Python 中的多线程最好用于处理赏罚有关 I/O 的操纵,如从网上下载资源可能从当地读取文件可能目次

最后,建设一个名称列表,然后行使 name要害字参数为每一个线程配置详细名称,这样就可觉得线程定名。运行以上代码,将会获得包括以下内容的日记文件:

  1. 2016-07-24 20:39:50,055 - Mike - DEBUG - doubler function executing 
  2. 2016-07-24 20:39:50,055 - Mike - DEBUG - doubler function ended with: 0 
  3. 2016-07-24 20:39:50,055 - George - DEBUG - doubler function executing 
  4. 2016-07-24 20:39:50,056 - George - DEBUG - doubler function ended with: 2 
  5. 2016-07-24 20:39:50,056 - Wanda - DEBUG - doubler function executing 
  6. 2016-07-24 20:39:50,056 - Wanda - DEBUG - doubler function ended with: 4 
  7. 2016-07-24 20:39:50,056 - Dingbat - DEBUG - doubler function executing 
  8. 2016-07-24 20:39:50,057 - Dingbat - DEBUG - doubler function ended with: 6 
  9. 2016-07-24 20:39:50,057 - Nina - DEBUG - doubler function executing 
  10. 2016-07-24 20:39:50,057 - Nina - DEBUG - doubler function ended with: 8 

输出功效不言自明,以是继承先容其他内容。在本节中再多说一点,即通过担任 threading.Thread实现多线程。举最后一个例子,通过担任 threading.Thread 建设子类,而不是直接挪用 Thread 函数。

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读