| 123456789101112131415161718192021 |
- import threading
- import time
- def print_numbers(threadName, delay):
- count = 0
- while count < 5:
- time.sleep(delay)
- count += 1
- print(f"{threadName}: {time.ctime(time.time())}")
- try:
- thread1 = threading.Thread(target=print_numbers, args=("Thread-1", 2))
- thread2 = threading.Thread(target=print_numbers, args=("Thread-2", 4))
- thread1.start()
- thread2.start()
- thread1.join()
- thread2.join()
- except Exception as e:
- print(f"Error: {e}")
|