@author jackzhenguo
@desc
@date 2019/10/21
118 默认启动主线程
一般的,程序默认执行只在一个线程,这个线程称为主线程,例子演示如下:
导入线程相关的模块 threading
:
import threading
threading的类方法 current_thread()
返回当前线程:
t = threading.current_thread()
print(t) # <_MainThread(MainThread, started 139908235814720)>
所以,验证了程序默认是在MainThead
中执行。
t.getName()
获得这个线程的名字,其他常用方法,getName()
获得线程id
,isAlive()
判断线程是否存活等。
print(t.getName()) # MainThread
print(t.ident) # 139908235814720
print(t.isAlive()) # True
大家在看
AI安装教程
AI本地安装教程
微软AI大模型通识教程
微软AI大模型通识教程
AI大模型入门教程
AI大模型入门教程
Python入门教程
Python入门教程
Python进阶教程
Python进阶教程
Python小例子200道练习题
Python小例子200道练习题
Python练手项目
Python练手项目
Python从零在线练习题
Python从零到一60题