简体   繁体   English

Stackless Python 中的 Tasklets 本地存储

[英]Tasklets Local Storage in Stackless Python

I'm starting with Stackless Python so it's a whole new amazing world for me.我从 Stackless Python 开始,所以这对我来说是一个全新的神奇世界。 I usually use regular threads, and they normally have Thread-local storage (TLS), which is a very useful feature when you need NOT share memory with other threads.我通常使用常规线程,它们通常具有线程本地存储 (TLS),当您不需要与其他线程共享 memory 时,这是一个非常有用的功能。

So, I'm wondering if Stackless Python has something similar: A way to store local memory (a python object) for a given tasklet.所以,我想知道 Stackless Python 是否有类似的东西:A way to store local memory (a python object) for a given tasklet。 Is that possible?那可能吗?

Thanks in advance.提前致谢。 -f -F

Solution1: The TLS can be simulated in stackless/greenlet using the current tasklet object, retrieved by the call of stackless.getcurrent(), to store additional data.解决方案 1:可以在 stackless/greenlet 中使用当前 tasklet object 模拟 TLS,通过调用 stackless.getcurrent() 检索,以存储附加数据。

Solution2: If the tasklet didn't support to add extra fields, than you can have a global WeakKeyDictionary instance that will have as weakref key the tasklet, and value represents your TLS.解决方案 2:如果 tasklet 不支持添加额外字段,那么您可以拥有一个全局WeakKeyDictionary实例,该实例将作为 tasklet 的弱引用键,并且 value 代表您的 TLS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM