Linux 拨号vps windows公众号手机端

python怎么同时运行多个函数

lewis 6年前 (2019-03-27) 阅读数 10 #程序编程
文章标签 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(fun1))

threads.append(threading.Thread(fun2))

print(threads)

if __name__ == '__main__':

for t in threads:

print(t)

t.start()

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门