Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- from time import time
- thread_count = 2
- class tthread (threading.Thread):
- def run (self):
- sum = 0
- for i in range (0, 1000000):
- sum = sum + i
- return sum
- threads = []
- for i in range (0, thread_count):
- t = tthread ()
- threads.append (t)
- threads [-1].start ()
- print ("Spawned and run")
- stime = time ()
- cdone = 0
- for t in threads:
- t.join ()
- ++cdone
- perc = (cdone / thread_count) * 100
- print (perc, "%")
- etime = time () - stime
- print (etime, " seconds")
- print ("Done")
Advertisement
Add Comment
Please, Sign In to add comment