I'm quite new to the threading module, but my problem is that threads appear to not start.I tried to use the currentThread function to see is they are new threads starting but the only thing I see is the Main thread.Also, in every tutorial I see they use classes or subclasses, like class t(threading.Thread). So is it my method that's wrong or do I have to use classes to start threads in python 3. Here is some scripts I wrote:
The first:
import threading
def basicThread(threadName,nr):
print("Thread name ",threadName,", alive threads ",nr)
for i in range(0,11):
print(threading.activeCount())
print(threading.currentThread())
t = threading.Thread(target = basicThread,args = ("Thread - %s" %i,i,))
t.start()
t.join()
Second :
import threading
def openFile():
try:
file = open("haha.txt","r+")
print("Finished in opening file : {0}".format(file))
except IOError as e:
print("Error : {0}".format(e))
def user(threadName,count):
age = int(input("Enter your age : "))
name = str(input("Enter your name : "))
print(age,name)
print(threadName,count)
threadList = []
thread_1 = threading.Thread(target = openFile)
thread_1.start()
thread_1.join()
thread_2 = threading.Thread(target = user,args = ("Thread - 2",threading.activeCount()))
thread_2.start()
thread_2.join()