本文实例讲述了Python自定义线程类。分享给大家供大家参考,具体如下:
一. 代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# -*- 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程序设计有所帮助。
原文链接:https://blog.csdn.net/chengqiuming/article/details/78601188