Python进阶(多线程)

Posted xingxingclassroom

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python进阶(多线程)相关的知识,希望对你有一定的参考价值。

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线程函数执行时间的影响

 

以上是关于Python进阶(多线程)的主要内容,如果未能解决你的问题,请参考以下文章