开发者

Tasklets Local Storage in Stackless Python

开发者 https://www.devze.com 2023-03-10 00:54 出处:网络
I\'m starting with Stackless Python so it\'s a whole new amazing world for me. I usually use regular threads, and they normally have Thread-local s开发者_StackOverflow中文版torage (TLS), which

I'm starting with Stackless Python so it's a whole new amazing world for me. I usually use regular threads, and they normally have Thread-local s开发者_StackOverflow中文版torage (TLS), which is a very useful feature when you need NOT share memory with other threads.

So, I'm wondering if Stackless Python has something similar: A way to store local memory (a python object) for a given tasklet. Is that possible?

Thanks in advance. -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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消