脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python自定义线程类简单示例

Python自定义线程类简单示例

2021-01-24 00:47chengqiuming Python

这篇文章主要介绍了Python自定义线程类,结合简单实例形式分析Python线程的定义与调用相关操作技巧,需要的朋友可以参考下

本文实例讲述了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自定义线程类简单示例

希望本文所述对大家Python程序设计有所帮助。

原文链接:https://blog.csdn.net/chengqiuming/article/details/78601188

延伸 · 阅读

精彩推荐