简体   繁体   中英

Tasklets Local Storage in Stackless Python

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 storage (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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