使用两个线程同时执行两个函数,

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()
View Code

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2021-06-01
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案