Carcigenicate

Thread test

Mar 23rd, 2014
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import threading
  2. from time import time
  3.  
  4. thread_count = 2
  5.  
  6. class tthread (threading.Thread):
  7.     def run (self):
  8.         sum = 0
  9.         for i in range (0, 1000000):
  10.             sum = sum + i
  11.         return sum
  12.  
  13. threads = []
  14.  
  15. for i in range (0, thread_count):
  16.     t = tthread ()
  17.     threads.append (t)
  18.     threads [-1].start ()
  19.  
  20. print ("Spawned and run")
  21.  
  22. stime = time ()
  23. cdone = 0
  24. for t in threads:
  25.     t.join ()
  26.     ++cdone
  27.     perc = (cdone / thread_count) * 100
  28.     print (perc, "%")
  29.  
  30.  
  31. etime = time () - stime
  32. print (etime, " seconds")
  33. print ("Done")
Advertisement
Add Comment
Please, Sign In to add comment