Properties of Thread, Launching Ways, and Parameters Passing
Learn about thread properties, ways of launching threads, and passing parameters in threads.
We'll cover the following...
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 threadingt = threading.current_thread( ) # returns current Thread objectprint("Current thread:", t) # prints thread name, identifier & statusprint("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
...