登录
首页精彩阅读Python自定义线程类简单示例
Python自定义线程类简单示例
2018-05-24
收藏

Python自定义线程类简单示例

这篇文章主要介绍了Python自定义线程类,结合简单实例形式分析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()


二. 运行结果


数据分析咨询请扫描二维码

客服在线
立即咨询