import threading def worker():#子线程要执行的具体逻辑代码函数 print(‘threading‘) t1 = threading.current_thread() time.sleep(9)#通过休眠模拟子线程异步逻辑 print(t1.getName()) new_t = threading.Thread(target=worker,name=‘dxc1‘)#构建子线程 new_t.start()#开启子线程 t = threading.current_thread()#构建主线程 print(t.getName())#主线程的代码执行不会受子线程的worker线程函数执行时间的影响
原文:https://www.cnblogs.com/xingxingclassroom/p/11145027.html