python

python怎么同时运行多个函数

九三
1259
2021-02-25 17:31:29
栏目: 编程语言

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
看了该问题的人还看了