Files
Python_CookBook_repo/12.并发/1.启动和停止线程.py

21 lines
353 B
Python
Raw Permalink Normal View History

2025-09-10 16:12:45 +08:00
import time
def countdown(n):
while n > 0:
print("T-minus", n)
n -= 1
time.sleep(5)
def countdown2(n):
while n > 0:
print("T-minus", n)
n -= 1
time.sleep(6)
from threading import Thread
t = Thread(target=countdown, args=(10, ))
t.start()
t2 = Thread(target=countdown2, args=(10, ))
t2.start()