gpt4 book ai didi

python - Python的struct.Struct对象是线程安全的吗?

转载 作者:太空宇宙 更新时间:2023-11-03 20:30:43 25 4
gpt4 key购买 nike

在Python中,有一个struct.Struct用于高效打包和解包数据的类,而不是始终调用 struct.pack。我想知道线程共享同一个 Struct 对象是否安全。文档没有提到线程安全,而且还有一个令人困惑的注释:

Note: The compiled versions of the most recent format strings passed to Struct and the module-level functions are cached, so programs that use only a few format strings needn’t worry about reusing a single Struct instance.

最佳答案

Struct 中没有使用临时状态变量,并且其所有属性(formatsize...)都是只读的,因此没有理由这样做您不能跨线程使用它。

关于python - Python的struct.Struct对象是线程安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57528698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com