How to make a parent thread wait either specified amount of time or until the child thread finishes?
Right now, my parent thread starts the child thread and then proceeds to time.sleep() a certain amount of time. Is there any way I can get my parent thread to sleep OR thread.join()? (If I remember right thread.join() is the one that waits for the child thread to finish)
thread = threading.Thread(target=whatever, args=yeah)
thread.start()
#here wait till either 60 seconds has passed or th开发者_运维问答e child thread finishes, which ever comes first
#if 60 passes stop child thread (I already have a way to do this)
#continue doing other stuff
Pass a 60 second timeout to the join() function:
thread.join(60)
After that call has returned, you can check if the thread joined or timed out based on the isAlive()
call.
精彩评论