import threading
def thread_job():
print('this is an added Thread, number is %s' % threading.current_thread())
def main():
# 添加一线程,这个线程执行target里,比如这里就是执行thread_job()
added_thread = threading.Thread(target=thread_job)
# 并运行这个线程
added_thread.start()
# 有多少个线程
print(threading.active_count())
# 查看是哪个线程
print(threading.enumerate())
# 查看正在运行的线程
print(threading.current_thread())
if __name__ == "__main__":
main()
2.join的应用
2.1 线程运行流程
import threading
import time
# 一个简单的function
def thread_job():
# print("This is an added Thread, number is %s "%threading.current_thread())
print("T1 start \n")
for i in range(10):
time.sleep(0.1)
print("T1 finish \n")
def main():
# 创建一个执行thread_job的线程
#