Advertisement
famansour

Tips&Tricks #run two separate functions simultaneously using Thread

Aug 26th, 2020
2,510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. # -------------------------------------------
  2. # (c) 2020 Fouad AMANSOUR fd.amansour@gmail.com
  3. # This code can run two separate functions simultaneously using Thread
  4. # -------------------------------------------
  5.  
  6.  
  7. import time
  8. from threading import Thread
  9.  
  10. def firstFunction():
  11.     while True:
  12.  
  13.         print('The 1st "while loop" is currently running')    
  14.         time.sleep(1)
  15.  
  16. def secondFunction():
  17.     while True:
  18.  
  19.         print('The 2nd "while loop" is currently running')    
  20.         time.sleep(1)
  21.    
  22. thread1  = Thread(target = firstFunction)
  23. thread2  = Thread(target = secondFunction)
  24.  
  25. thread1 .start()
  26. thread2.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement