import threading # 线程模块 def function(num): pass thread_1 = threading.Thread(target=function, args=(1,)) # 创建线程 thread_1.start() # 启动线程 thread_1.getName() # 获取线程名 thread_1.join() # 线程阻塞,等待完成当前线程在开始执行下一个 lock = threading.Lock() # 初始化线程锁 lock.acquire() # 线程加锁 lock.release() # 线程锁释放 with lock: # 自动释放线程锁 pass # 业务代码