python name a thread code example
Example 1: how to change a thread name in python
import threading
threding.current_thread().name = "name_of_the_thread"
Example 2: python daemon thread
import threading
import time
def print_work_a():
print('Starting of thread :', threading.currentThread().name)
time.sleep(2)
print('Finishing of thread :', threading.currentThread().name)
def print_work_b():
print('Starting of thread :', threading.currentThread().name)
print('Finishing of thread :', threading.currentThread().name)
a = threading.Thread(target=print_work_a, name='Thread-a')
b = threading.Thread(target=print_work_b, name='Thread-b')
a.start()
b.start()