创建一个多线程
from threading import Thread, ThreadError
import time
def task_01():
print("开始发送邮件")
time.sleep(1)
print("邮件发送成功")
if __name__ == "__main__":
t1 = Thread(target=task_01)
# 线程开始
t1.start()
# 查看子线程状态
print(f"查询子线程的状态{t1.is_alive()}")
time.sleep(0.3) # 休息三秒
try:
t1.start()
except ThreadError as e:
print("Thread.start 只能被调用一次,重复调用会报错", e)
print(f"err is {e}")
print("主线程依旧可以干别的事情")
print(f"t1 的名字 {t1.name}")
time.sleep(1)
print(f"查询子线程的状态 {t1.is_alive()}")
标签:__,python,t1,线程,time,print,多线程
From: https://www.cnblogs.com/rush-peng/p/17100201.html