线程、守护线程、互斥锁
'''
线程:执行代码的分支,程序默认会有一个线程(主线程)
'''
import threading, time
def AA(count):
for i in range(count):
print('AA')
time.sleep(0.3)
def BB(count):
for i in range(count):
print('BB')
print(threading.current_thread().getName())
if __name__ =='__main__':
#创建子线程(执行代码)
sub_thread = threading.Thread(target = AA, args=(5,))
three_thread = threading.Thread(target= BB, kwargs={'count':5})
# 设置守护线程,主线程结束,子线程也结束
sub_thread.setDaemon(True)
#sub_thread = threading.Thread(target = AA, args=(5,), daemon= True)
#启动线程
#线程只能启动(调用)一次
#线程执行没有顺序,跟cpu调度相关
sub_thread.start()
three_thread.start()
#获取当前线程的名字
print(threading.current_thread().getName())
sub_thread.setName(&