本文实例讲述了Python自定义线程类。分享给大家供大家参考,具体如下:一.代码#-*-coding:utf
本文实例讲述了Python自定义线程类。分享给大家供大家参考,具体如下:
一. 代码
# -*- coding:utf-8 -*-
#! python2
import threading
class mythread(threading.Thread):
def __init__(self, num):
threading.Thread.__init__(self)
self.num = num
def run(self):
print('I am {0}'.format(self.num))
t1 = mythread(1)
t2 = mythread(2)
t3 = mythread(3)
t1.start()
t2.start()
t3.start()
二. 运行结果
Python 自定义 线程类