【发布时间】:2022-06-24 00:11:28
【问题描述】:
我正在考虑运行一些代码以每 X 分钟自动保存一次游戏,但它也有一个接受键盘输入的线程。这是我试图同时运行的一些示例代码,但它们似乎一个接一个地运行。如何让它们同时运行?
import time
import threading
def countdown(length,delay):
length += 1
while length > 0:
time.sleep(delay)
length -= 1
print(length, end=" ")
countdown_thread = threading.Thread(target=countdown(3,2))
countdown_thread2 = threading.Thread(target=countdown(3,1))
countdown_thread.start()
countdown_thread2.start()
【问题讨论】:
标签: python