Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # std lib modules. "Batteries included" FTW.
- import threading
- import time
- thread_result = -1
- def ThreadWork():
- global thread_result
- thread_result = 1 + 1
- time.sleep(5) # phew, I'm tiered after all that addition!
- my_thread = threading.Thread(target=ThreadWork)
- my_thread.start() # This will call ThreadWork in the background.
- # In the mean time, you can do other stuff
- y = 2 * 5 # Completely independent calculation.
- my_thread.join() # Wait for the thread to finish doing it's thing.
- # This should take about 5 seconds,
- # due to time.sleep being called
- print "thread_result * y =", thread_result * y
Add Comment
Please, Sign In to add comment