学习笔记(29):Python网络编程&并发编程-信号量
2023-09-11 14:21:45 时间
立即学习:https://edu.csdn.net/course/play/24458/296446?utm_source=blogtoedu
信号量(了解):也是一把锁semaphore
1.
from threading import Thread,Semaphore,currentThread
import time
#定义信号量(3把锁)
sm = Semaphore(3)
def task():
with sm:
print('%s acquires the sm' % currentThread().getName())
time.sleep(1)
if __name__ == '__main__':
for i in range(10):
t = Thread(target=task)
t.start()
2.
sm.acquire()
print('%s acquires the sm'%currentThread().getName())
sm.release()
#等价于
with sm:
print('%s acquires the sm'%currentThread().getName())
相关文章
- python是否存在某个字符串 效率最高_Python中判断子串存在的性能比较及分析总结...
- 【华为OD机试真题 python】最差产品奖【2023 Q1 | 200分】
- Python && JAVA 去除字符串中空格的五种方法
- Python零基础入门,2分钟带你了解python
- 人生苦短,我用Python!为什么现在越来越多的人转行python?
- Python: threading.Semaphore & threading.BoundedSemaphore & GIL
- python, 私有属性详解
- 如何基于pycharm进行python远程调试
- 专家有奖问答|Python爬虫Q&A
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- Python Kivy安装及使用PyCharm进行简单测试(讲解如何参照kivy官方说明安装测试)
- Python 工具 之 Windows 上 python 虚拟环境的搭建与简单使用的相关说明
- python第三十课--异常(异常对象传递过程)
- python第二十八课——编码小常识
- 学习笔记(36):Python网络编程&并发编程-IO模型介绍
- 学习笔记(33):Python网络编程&并发编程-进程池线程池
- 学习笔记(32):Python网络编程&并发编程-线程queue
- 学习笔记(27):Python网络编程&并发编程-GIL与多线程
- 学习笔记(25):Python网络编程&并发编程-Thread其他属性和守护线程
- 学习笔记(19):Python网络编程&并发编程-互斥锁
- 学习笔记(18):Python网络编程&并发编程-守护进程
- 学习笔记(17):Python网络编程&并发编程-Process对象的其他属性或方法
- 学习笔记(12):Python网络编程&并发编程-解决粘包问题-简单版本
- 学习笔记(08):Python网络编程&并发编程-实现服务端可以对多个客户端提供服务
- np.zeros的问题&&python错误:TypeError: Cannot interpret ‘3‘ as a data type