I'm new to threads and am executing a very basic thread example. The following is the program I'm trying to execute:
import os
import thread
import threading
def main():
t1=thread.start_new_thread(prints,(3,))
t2=thread.start_new_thread(prints,(5,))
t1.start()
t2.start()
#t1.join()
#t2.join()
def prints(i):
while(i>0):
print "i="+str(i)+"\n"
i=i-1
if __name__=='__main__':
main()
When I try and execute, I keep getting the following error (AttributeError: 'int' object has no attribute 'start'):
Traceback (most recent call last):
i=3
File "thread_1.py", line 19, in <module>
i=2
i=1
main()
i=5
i=4
i=3
i=2
i=1
File "thread_1.py", line 8, in main
t1.start()
AttributeError: 'int' object has no attribute 'start'
As can be seen from the output, both are getting executed but not the way I was expecting it to (which is interleaved prints or something like that). It seems more sequential too. How can I modify/correct my program to get the expected output?