通过一下示例:
from threading import Thread import threading def func1(): print('f1',threading.current_thread().name) def func2(): # print('f2',threading.current_thread().name) t2 = Thread(target= func1) t2.start() print('f2', threading.current_thread().name) def func3(): t3 = Thread(target=func2) t3.start() print('f3',threading.current_thread().name) # def func4(): # print('f4',threading.current_thread().name) if __name__ == '__main__': s = Thread(target= func3) s.start() print('主', threading.current_thread().name)
打印结果:
主 MainThread f3 Thread-1 f1 Thread-3 f2 Thread-2