参考博客: www.cnblogs.com/yuanchenqi/articles/5733873.html
semaphore 信号量:
condition 条件变量:
event 同步条件:条件同步和条件变量同步差不多意思,只是少了锁功能。因为条件同步设计于别访问共享资源的条件环境
多线程利器(queue):队列本身有一把锁
q.put(‘xiaoming’, 0)
q.get(0)
q.qsize() 返回队列大小
q.empty()
q.full()
semaphore:
# _author: lily # _date: 2019/1/29 import threading , time class MyThread(threading.Thread): def run(self): if semaphore.acquire(): print(self.name) time.sleep(3) semaphore.release() if __name__ == '__main__': semaphore = threading.BoundedSemaphore(5) thread_list = [] for i in range(100): thread_list.append(MyThread()) for i in thread_list: i.start()