G
Gurpreet Sachdeva
I have written a code to figure out the difference in excecution time
of a func before and after using threading...
Some times this code executes and some times it hangs to death
(
Am I am doing something wrong?? Also the difference of time is not much...
How do we best optimize our task by using threads... please help...
Thanks and Regards,
Gurpreet Singh
of a func before and after using threading...
Code:
#!/usr/bin/env python
import threading
import time
loops = [5000,5000]
def loop(self, nsec):
for i in range(1,nsec):
t=i*5000
s=t/10*15555
def main():
threads = []
nloops = [0,1]
for i in nloops:
print '\nSpawning Thread',i,' value: ',loops[i]
t = threading.Thread(target=loop,args=(i, loops[i]))
threads.append(t)
for i in nloops: # start threads
threads[i].start()
for i in nloops: # wait for all
threads[i].join
if __name__ == '__main__':
start = time.clock()
loop(1,5000)
print 'Time Taken: ', time.clock()-start
start = time.clock()
main()
print 'Time Taken: ', time.clock()-start
Some times this code executes and some times it hangs to death
Am I am doing something wrong?? Also the difference of time is not much...
How do we best optimize our task by using threads... please help...
Thanks and Regards,
Gurpreet Singh