导入线程模块
import threading
2,通过线程类创建线程对象线程对象 = threading.Thread(target=任务名)
target:执行的目标任务名,这里指的是函数名(方法名)
name:线程名,一般不用设置
group:线程组,目前只能使用None
3,启动线程执行任务线程对象.start()
4,线程创建与启动的代码# 创建子线程 test_1 = threading.Thread(target=test) # 启动线程 test_1.start()5,示例
import threading # 导入线程模块
import time
def test():
for i in range(3):
print(i)
time.sleep(1)
def test2():
for i in range(3):
print(i)
time.sleep(1)
if __name__ == '__main__':
test_1 = threading.Thread(target=test)
test_2 = threading.Thread(target=test2)
test_1.start()
test_2.start()



