摘要: asyncio也存在锁机制,可以保证在同一时刻只有一个协程访问资源。 关键方法是acquire与release。前者会创建一个future对象并加入队列,然后await这个future对象。release方法则取出这个对象并设置结果。 acquire方法关键代码片段 if self._waiters 阅读全文
posted @ 2025-06-21 21:28 LRJ313 阅读(37) 评论(0) 推荐(0)
摘要: 先看一个例子 from typing import Sized class MyLen: def __len__(self): return 10 print(issubclass(MyLen, Sized)) print(MyLen.__mro__) 输出为True,但是我们没有显示继承Sized 阅读全文
posted @ 2024-12-26 18:42 LRJ313 阅读(42) 评论(0) 推荐(0)
摘要: dst是一个基于go语言实现的,操纵ast的第三方库。 文件解析、修改与写入的一般流程: content, _ := os.ReadFile(root_path) f, _ := decorator.ParseFile(nil, root_path, content, parser.ParseCom 阅读全文
posted @ 2024-11-22 19:48 LRJ313 阅读(94) 评论(0) 推荐(0)
摘要: 对类进行索引 翻阅python源码有时会看到类似这样的实现,class Dataset(Generic[T_co]):Generic是一个类,但是可以直接对其进行索引,这需要归功于魔法方法__class_getitem__。 class Box: def __class_getitem__(cls, 阅读全文
posted @ 2024-11-14 22:16 LRJ313 阅读(318) 评论(0) 推荐(0)