并发编程——线程——Thread对象的属性和方法

Thread实例对象的方法

  # isAlive(): 返回线程是否活动的。
  # getName(): 返回线程名。
  # setName(): 设置线程名。

threading模块提供的一些方法:

  # threading.currentThread(): 返回当前的线程变量。
  # threading.enumerate(): 返回一个包含正在运行的线程的list。正在运行指线程启动后、结束前,不包括启动前和终止后的线程。
  # threading.activeCount(): 返回正在运行的线程数量,与len(threading.enumerate())有相同的结果。
import threading
from threading import Thread


def task():
    import time
    time.sleep(2)
    

猜你喜欢

转载自blog.csdn.net/weixin_43336281/article/details/104213582
今日推荐