# !/usr/bin/python
# -*- coding:utf-8 -*-
# ++++++++++++++++++++
# author: FMspider
# time: 2018-5-3 9:11
# function: 使用类创建线程的方法
import time
import threading
class MyThread(threading.Thread): # 继承父类
def __init__(self, num):
threading.Thread.__init__(self) # 初始化父类的代码,初始化这个对象的基类部分
self.num = num
def run(self): # 定义每个线程要运行的函数
print("running on number: %s" %self.num)
time.sleep(4)
if __name__ == '__main__':
t1 = MyThread(1)
t2 = MyThread(2)
t1.start()
t2.start()
使用类来创建线程的方法
最新推荐文章于 2021-03-20 22:25:39 发布