2011-07-06 5 views
1

私の親スレッドは子スレッドを開始してから、ある時間だけtime.sleep()に進みます。親スレッドをスリープ状態にする方法や、thread.join()を呼び出す方法はありますか? 親スレッドは、指定された時間だけ待機するか、子スレッドが終了するまで待つか?

thread = threading.Thread(target=whatever, args=yeah) 
thread.start() 
#here wait till either 60 seconds has passed or the 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 

答えて

6

が参加()関数に60秒のタイムアウトを渡します(私は()子スレッドが終了するのを待って1である右thread.joinを覚えている場合):

thread.join(60) 

後その呼び出しが返された場合、isAlive()呼び出しに基づいて、スレッドが参加したかタイムアウトしたかを確認できます。

関連する問題