0
2つの関数を同時に実行して、両方がTrueを返してから最大60秒のタイムアウトになるまでします。スレッド測定時間を使用して複数の関数を実行するにはどうすればよいですか?
これは私が持っているものです。
import time
start_time = time.time()
timeout = time.time() + 60
a_result = b_result = False
a_end_time = b_end_time = None
a_duration = b_duration = None
while time.time() < timeout :
if not a_result:
a_result = func_a()
if a_result:
a_end_time = time.time()
if not b_result:
b_result = func_b()
if b_result:
b_end_time = time.time()
if a_result and b_result:
break
if a_end_time:
a_duration = a_end_time - start_time
if b_end_time:
b_duration = b_end_time - start_time
print a_duration,b_duration
if not (a_result and b_result):
raise Exception("exceeded timeout")
どのように私はこの使用してスレッドを向上させることができますか?