Advertisement
GoodiesHQ

ThreadExample1.py

Nov 30th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import time
  2. import threading
  3.  
  4. def func(time_to_sleep):
  5.     time.sleep(time_to_sleep)  # this sleep occurs inside the new thread
  6.     print("func() completed")
  7.  
  8. t = threading.Thread(target=func, args=(0.5,))
  9. t.start()  # the flow of execution in the main thread immediately goes to the next statement
  10. print("Thread Started")  # this is printed without sleeping since the sleep function is called in the spawned thread
  11. t.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement