1. current_thread main process and sub-processes are displayed as MainThread, but different meanings
---- MainThread main process represents the main process of the main thread name
---- MainThread child processes represent the child process is the main thread name
#进程的current_thread from threading import Thread,current_thread from multiprocessing import Process import time def work(): print("target %s is running" %current_thread().getName()) time.sleep(2) print("target %s is done" %current_thread().getName()) if __name__=="__main__": p=Process(target=work) p.start() print("主",current_thread().getName()) ''' 主 MainThread target MainThread is running target MainThread is done '''
1. Different main thread and the child thread of current_thread
#线程的current_thread from threading import Thread from threading import activeCount,enumerate from threading import current_thread import time def work(): print("target %s is running" %current_thread().getName()) time.sleep(2) print("target %s is done" %current_thread().getName()) if __name__=="__main__": t1=Thread(target=work) t1.start() print("主",current_thread().getName()) ''' target Thread-1 is running 主 MainThread target Thread-1 is done '''