【笔记】Python3的多线程

前言

Python3的多线程

定义类

  • 定义一个类,实现threading.Thread接口,重写run()方法
1
2
3
class 类名(threading.Thread):
def run(self):
...

实例化对象

1
t = 类名()

启动线程

1
t.start()

获取所有正在运行的线程对象

1
t_list = threading.enumerate()

获取所有正在运行的线程个数

1
t_list_length = threading.active_count()

线程的名称

设置线程的名称

1
t.setName("")

获取线程的名称

1
t.getName()

完成

参考文献

菜鸟笔记