...

/

Properties of Thread, Launching Ways, and Parameters Passing

Properties of Thread, Launching Ways, and Parameters Passing

Learn about thread properties, ways of launching threads, and passing parameters in threads.

Thread properties

Every running thread has a name and a number called a thread identifier associated with it.

The names of all running threads don’t need to be unique. However, the identifier must be unique. The identifier can be reused for other threads if the current thread ends.

Press + to interact
import threading
t = threading.current_thread( ) # returns current Thread object
print("Current thread:", t) # prints thread name, identifier & status
print("Thread name:", t.name)
print("Thread identifier:", t.ident)
print("Is thread alive:", t.is_alive( ))
t.name = 'MyThread'
print("After name change:", t.name)

In the code above, current_thread() is a function defined in the threading ...