Guest User

Untitled

a guest
Jan 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # std lib modules. "Batteries included" FTW.
  2. import threading
  3. import time
  4.  
  5. thread_result = -1
  6.  
  7. def ThreadWork():
  8. global thread_result
  9. thread_result = 1 + 1
  10. time.sleep(5) # phew, I'm tiered after all that addition!
  11.  
  12. my_thread = threading.Thread(target=ThreadWork)
  13. my_thread.start() # This will call ThreadWork in the background.
  14. # In the mean time, you can do other stuff
  15. y = 2 * 5 # Completely independent calculation.
  16. my_thread.join() # Wait for the thread to finish doing it's thing.
  17. # This should take about 5 seconds,
  18. # due to time.sleep being called
  19. print "thread_result * y =", thread_result * y
Add Comment
Please, Sign In to add comment