python threading多线程
多线程threading模块例子
import threading
import time
flag = True
def fun01():
global flag
time.sleep(5)
flag = False if flag else True
print("flag:" + str(flag))
def fun02():
begin_time = time.time()
wait_time = 6
while 1:
if time.time() - begin_time > wait_time:
raise Exception("Time out")
elif not flag:
print("Start")
break
else:
continue
t1 = threading.Thread(target=fun01)
t2 = threading.Thread(target=fun02)
t1.start()
t2.start()