Overview:
- This property of the Thread class allows a Python Thread instance to be a given a name.
- Generally developers would like to identify threads created from their programs with some sort of naming scheme. The name property comes handy here.
- Remember, multiple threads can be given same name by the developer. It is up to the developer to give meaningful names for one or more threads.
- The following Python Program creates a thread and gives its name CustomThread followed by a numeric suffix.
Example:
from threading import Thread
def ThreadFunction(): print("Inside thread Body")
customThread = Thread(target=ThreadFunction()) customThread.name = "CustomThread{}".format(1) print(customThread.name) customThread.start() customThread.join()
print("Main thread resumed") print("Main thread exiting")
|
Output:
Inside thread Body CustomThread1 Main thread resumed Main thread exiting |