I have written a code to figure out the difference in excecution time
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
[/CODE]

Some times this code executes and some times it hangs to death :o(
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
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to