Python实战笔记(三) 多线程
Python 提供 threading 模块用于控制线程,使我们处理多线程更加方便 1、线程模块的常用属性和方法 active_count() :返回当前存活的线程对象的数量 enumerate() :返回当前存活的线程对象的列表 current_thread() :返回当前线程对象 main_thread() :返回主线程对象 get_ident() :返回当前线程的线程标识符 stack_size([size]) :返回创建线程时使用的堆栈大小 TIMEOUT_MAX :指定阻塞函数(如 acquire 、 wait 、 wait_for 等)timeout 参数的最大值 import threading thread_number = threading.active_count() print(thread_number) # 1 curr_thread = threading.main_thread() main_thread = threading.current_thread() print(curr_thread == main_thread) # True 2、创建线程对象 threading.Thread(group, target, name, args, kwargs, *, daemon) group:为拓展 ThreadGroup 而保留,无需设置