随笔 - 139  文章 - 0  评论 - 0  阅读 - 43242
03 2025 档案
python 简易协程池
摘要:"""简易协程池"""import asynciofrom typing import Any​​async def async_task(semaphore, coro) -> Any: async with semaphore: # 使用信号量来限制并发数量 res = await coro r 阅读全文
posted @ 2025-03-13 15:28 CJTARRR 阅读(0) 评论(0) 推荐(0) 编辑
python 异步读写锁
摘要:import asyncio​​class AsyncReadWriteLock: def __init__(self): self._readers = 0 self._writers_waiting = 0 self._writer_active = False self._lock = asy 阅读全文
posted @ 2025-03-13 15:06 CJTARRR 阅读(2) 评论(0) 推荐(0) 编辑
python shared_memory 共享内存
摘要:背景 python利用多核就需要开启多进程,如果多进程之间需要共享数据又不希望引入第三方的服务,就需要使用共享内存。 multiprocessing.shared_memory python 3.8之后,python内置的multiprocessing库提供了一种新的共享内存方式,shared_me 阅读全文
posted @ 2025-03-13 09:45 CJTARRR 阅读(10) 评论(0) 推荐(0) 编辑
python redis[hiredis]使用
摘要:安装 pip install "redis[hiredis]" 检查是否启用hiredis import redisimport redis.connectionfrom redis.connection import ConnectionPoolfrom redis.utils import HI 阅读全文
posted @ 2025-03-12 16:23 CJTARRR 阅读(1) 评论(0) 推荐(0) 编辑
pymongo字符串模糊查询
摘要:import re options = "i" regex_pattern = re.escape(字符串) query = {"$regex": regex_pattern, "$options": options} 结果 = 集合.find(query) # 这里用re.escape套一下字符串 阅读全文
posted @ 2025-03-12 09:33 CJTARRR 阅读(2) 评论(0) 推荐(0) 编辑
fastapi中间件异常处理
摘要:1.在fastapi的中间件中,如果不做处理直接抛出HttpException,框架是不会捕获并处理成响应的,这时客户端看到的就是500 Internal Server Error。 2.为了能在中间件中直接抛出异常,方便写代码,需要自己添加一个中间件来对所有中间件的异常做处理。该中间件代码如下: 阅读全文
posted @ 2025-03-07 09:50 CJTARRR 阅读(13) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示