Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import time
- def t1():
- for _ in range(5):
- print("Thread 1")
- time.sleep(1)
- def t2():
- for _ in range(5):
- print("Thread 2")
- time.sleep(1)
- # Create thread objects
- thread1 = threading.Thread(target=t1)
- thread2 = threading.Thread(target=t2)
- # Start the threads
- thread1.start()
- thread2.start()
- # Wait for both threads to finish
- thread1.join()
- thread2.join()
Advertisement
Add Comment
Please, Sign In to add comment