有时候join()我们是用来连接字符串的, 但就在今天我学习进程的时候, 看见 join(), 居然不是用来连接字符串了, 而是用来阻塞进程, 兴趣大增, 便深入了解了一下, join()的作用: 在进程中可以阻塞主进程的执行, 直到等待子线程全部完成之后, 才继续运行主线程后面的代码 我们先来看下面的代码, 这段代码没有使用join() 代码段A import threading import time def test(num): time.sleep(1) print(num) #定义一个用来装子线程的列表 threads = [] for i in range(5): #target 指定子线程要执行的funtion, args 指定该funtion需要传入的参数 thread = threading.Thread(target = test, args = [i]) #上面的 thread 是一个个参数i都不同的线程, 现在把它一个个装进列表 threads 里面 threads.append(thread) for i in tsreads: #for 循环执行 threads 列表里面的全部线程, 没有用 join()线程是无序执行的, # 就连最后一句print('end')可能比所有子线程都要先执行 i.start() print('end') 执行结果,