Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import threading
- def func(time_to_sleep):
- time.sleep(time_to_sleep) # this sleep occurs inside the new thread
- print("func() completed")
- t = threading.Thread(target=func, args=(0.5,))
- t.start() # the flow of execution in the main thread immediately goes to the next statement
- print("Thread Started") # this is printed without sleeping since the sleep function is called in the spawned thread
- t.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement