Python线程同步
我有 3 个任务:t1、t2 和 t3。 我想在两个并行线程中运行 t1 和 t2。我想等待 t1 和 t2 执行结束后再运行 t3。
t1 =========> |
t2 ====> |
t3......................|=======>
-------------------------------------------------- -----------(时间)-->
我对线程同步有一些基础,但我不知道如何管理这种情况。 python 库中是否有任何内置解决方案,我是否必须编写自己的(基于信号量?)解决方案?
I have 3 tasks : t1, t2 and t3.
I want to run t1 and t2 in two parallels threads. And I want to wait for the end of t1 and t2 execution before running t3.
t1 =========> |
t2 ====> |
t3......................|=======>
-------------------------------------------------------------(time)-->
I have some basis about threads synchronization but I can't find out how to manage with this case.
Is there any build-in solution in python library did I have to write a my own (semaphore based ?) solution ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
join
:You can wait on threads with
join
:我建议您查看模块
threading
。它提供锁定对象,条件对象 和 信号量对象。I would advise you to have a look at the module
threading
. It provides lock objects, condition objects and semaphore objects.