Python thread synchronisation
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 ?
You can wait on threads with join
:
# start the two threads
t1.start()
t2.start()
# wait until both ended
t1.join()
t2.join()
# then start the third
t3.start()
I would advise you to have a look at the module threading
. It provides lock objects, condition objects and semaphore objects.
精彩评论