溫馨提示×

python如何同時運行兩個函數

九三
3121
2021-03-01 18:55:50
欄目: 編程語言

python如何同時運行兩個函數

在python中利用線程同時運行兩個函數,具體方法如下:

def fun1():

while True:

time.sleep(2)

print("fun1")

def fun2():

while True:

time.sleep(6)

print("fun2")

threads = []

threads.append(threading.Thread(target=fun1))

threads.append(threading.Thread(target=fun2))

print(threads)

if __name__ == '__main__':

for t in threads:

print(t)

t.start()

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女