app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import time from threading import Thread # Function 1 def countdown(n): while n > 0: print('T-minus', n) n -= 1 time.sleep(1) # Function 2 def print_messages(msg, count): for i in range(count): print(f"Message: {msg} ({i+1})") time.sleep(1.5) # Create and start threads t1 = Thread(target=countdown, args=(5,)) t2 = Thread(target=print_messages, args=("Hello from thread 2", 5)) t1.start() t2.start() # Optional: wait for both threads to finish t1.join() t2.join() print("Both threads have finished.") |