栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python线程中的join()有什么用?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python线程中的join()有什么用?

展示这种机制的技术有些笨拙:

join()
大概是由主线程调用的。也可以由另一个线程调用它,但是会不必要地使该图复杂化。

join
-调用应该放在主线程的轨道上,但是为了表达线程关系并使它尽可能简单,我选择将其放在子线程中。

without join:+---+---+------------------          main-thread    |   |    |   +...........      child-thread(short)    +..................................         child-thread(long)with join+---+---+------------------***********+###      main-thread    |   |       |    |   +...........join() |         child-thread(short)    +......................join()......         child-thread(long)with join and daemon thread+-+--+---+------------------***********+###     parent-thread  |  |   |       |  |  |   +...........join() |        child-thread(short)  |  +......................join()......        child-thread(long)  +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,     child-thread(long + daemonized)'-' main-thread/parent-thread/main-program execution'.' child-thread execution'#' optional parent-thread execution after join()-blocked parent-thread could     continue'*' main-thread 'sleeping' in join-method, waiting for child-thread to finish',' daemonized thread - 'ignores' lifetime of other threads;    terminates when main-programs exits; is normally meant for     join-independent tasks

因此,您看不到任何更改的原因是因为您的主线程在之后没有执行任何操作

join
。您可以说
join
(仅)与主线程的执行流相关。

例如,如果您想同时下载一堆页面以将它们串联成一个大页面,则可以使用线程开始并发下载,但是需要等到最后一页/线程完成后才能开始组装单个页面在很多。那是您使用的时间

join()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/612053.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号