Advertisement
GoodiesHQ

Threading_Tutorial_01.py

Mar 20th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 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()                            # blocks execution of main thread until 't' has completed and returns
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement