zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Python自定义线程类简单示例

Python线程 简单 自定义 示例
2023-09-14 08:58:52 时间

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()


二. 运行结果