python利用线程实现多任务
我们怎么让一个 Python 程序里边实现多任务呢? 实现多任务可以有多种方式,这里我们先了解使用线程的方式实现多任务。 线程是实现多任务的一种的手段。 其实用的是 threading 模块,threading 模块里有一个类叫 Thread。 Python 的 thread 模块是比较底层的模块,Python 的 threading 模块是对 thread 做了一些包装的,可以更加方便的被使用。 一、通过构造器传函数的方式创建线程 我们先来看一个实例: import time import threading def saySorry(): print(亲爱的,我错了,我能吃饭了么
下载地址
用户评论