相信读过《Python核心编程》的朋友们肯定注意到,这本书在讲解threading模块的Thread类时提出了这样一个创建线程的方法,即派生Thread的子类,并创建子类的实例。
书中的示例代码如下:
import threading
from time import sleep, ctime
loops = (4, 2)
class MyThread(threading.Thread):
def __init__(self, func, args, name=''):
threading.Thread.__init__(self)
self.name = name
self.func = func
self.args = args
def run(self):
self.func(*self.args)
def loop(nloop, nsec