SaltCat's recent timeline updates
SaltCat

SaltCat

V2EX member #435227, joined on 2019-08-11 18:10:41 +08:00
SaltCat's recent replies
> 一毫秒都无法接受

rust + tokio 吧.
Dec 7, 2020
Replied to a topic by IVeverKB Python 新手 关于 Python 协程的一个问题
用 asyncio.Lock,还有就直接 asyncio 技术栈一把嗦吧,asyncio 的侵入性感觉还是太强了。。。
mirai 自己写吧
Dec 2, 2020
Replied to a topic by abersheeran Python 关于协程转线程的一个问题
感觉你的表述并不清楚: 你没有说是如何从 coroutine send msg 到 thread 进行处理的(try contextvars); 第一个写的消息被覆盖, 是否考虑使用类似 stack 这样的数据结构 + property 防止覆盖? 如果涉及到同 /异步上下文传递, 可以考虑 `contextvars` 这个库: asyncio 在执行协程时会复制一份当前的上下文来执行, 从而避免出现覆写的问题;
希望能解决你的问题.
我好久都不用直接 json 序列化了, 上次用是 custom FastAPI 的 Response, 自己造了个 OrjsonResponse(后面官方提供了), 就用了 singledispacherxxxxx 和这个特性.
使用 json.dumps 的 default 参数:

```
json.dumps(sth, default=lambda x: x.toNative() if isinstance(x, MyCustomFloat) else None)
```
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   974 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 17ms · UTC 23:40 · PVG 07:40 · LAX 16:40 · JFK 19:40
♥ Do have faith in what you're doing.