多线程的建立与使用 目录 生成线程的三种方法 单线程与多线程对比 守护线程的设置 1 生成线程的三种方法 三种方式分别为: 创建一个Thread实例,传给它一个函数 创建一个Thread实例,传给它一个可调用的类实例 派生Thread的子类,并创建子类的实例 # There are three ways to create a thread # The first is create a thread instance, and pass a function # The second one
import time,threading print("=======串行方式.并行两种方式调用run()函数=======")def run(): print('哈哈哈') #串行for i in range(5): run() #并行for i in range(5): t = threading.Thread(target=run) #实例化了一个线程 t.start() print("======串行.并行方式统计网页下载时间=======") impor