0

Hello this is my code but idk why is the getName() crossed out??? [picture][1]
btw i use python [1]: https://i.stack.imgur.com/wHWm2.png

import time

def functionOne() :
    print(threading.current_thread().getName()+ str (' is starting \n'))
    time.sleep(2)
    print(threading.current_thread().getName() + str (' is exiting \n'))
    return

def functionTwo():
    print(threading.current_thread().getName() + str (' is starting \n'))
    time.sleep(2)
    print(threading.currentthread().getName() + str (' is exiting \n'))
    return

def functionThree():
    print(threading.currentthread().getName() + str (' is starting \n'))
    time.sleep(2)
    print(threading.currentthread().getName() + str (' is exiting \n'))
    return

if __name__ == "__main__":
    t1 = threading.Thread(name='functionOne',target=functionOne)
    t2 = threading.Thread(name='functionTwo',target=functionTwo)
    t3 = threading.Thread(name='functionThree',target=functionThree)

    t1.start();
    t2.start();
    t3.start(); 

Alvan D
  • 11
  • 1
  • 1
  • 1
    Why `currentthread` and `current_thread`? See https://stackoverflow.com/questions/919897/how-to-obtain-a-thread-id-in-python – user2864740 Oct 21 '21 at 04:53

1 Answers1

3

getName() has been recently deprecated, according to the docs:

Deprecated getter/setter API for name; use it directly as a property instead.

Deprecated since version 3.10.

Thus I presume you are running Python 3.10, so use this instead:

threading.current_thread().name

Also note the comment - later code uses currentthread() without an underscore, so that needs to be corrected too.

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114