主线程与子线程的关系

通过一下示例:

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
posted @ 2019-12-14 17:09  躺云飘  阅读(322)  评论(0编辑  收藏  举报