Python threading - threads do not start

I am new to the stream module, but my problem is that the threads are not starting. I tried using the currentThread function to see if they are new threads, but the only thing I see is the Main thread. In addition, in every tutorial, I see that they use classes or subclasses such as class t (threading.Thread). So this is my method that is wrong or I need to use classes to start threads in python 3. Here are some scripts I wrote:

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()

The 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()
+4
source share
2 answers

thread.join() , , . , .

+4
  • current_thread() , . , "basicThread", , ( ).

  • thread_1.join() ,

+1

Source: https://habr.com/ru/post/1526052/


All Articles