naren_paste

threading_1

Oct 11th, 2023
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | Source Code | 0 0
  1. import threading
  2. import time
  3.  
  4. def t1():
  5.     for _ in range(5):
  6.         print("Thread 1")
  7.         time.sleep(1)
  8.  
  9. def t2():
  10.     for _ in range(5):
  11.         print("Thread 2")
  12.         time.sleep(1)
  13.  
  14. # Create thread objects
  15. thread1 = threading.Thread(target=t1)
  16. thread2 = threading.Thread(target=t2)
  17.  
  18. # Start the threads
  19. thread1.start()
  20. thread2.start()
  21.  
  22. # Wait for both threads to finish
  23. thread1.join()
  24. thread2.join()
  25.  
Advertisement
Add Comment
Please, Sign In to add comment