At 19:18 30.06.2004 +0100, Armin Rigo wrote: >Hello Jim, > >On Wed, Jun 30, 2004 at 10:24:26AM -0400, Jim Fulton wrote: > > Here is a demonstration Python implementation: > > > > from threading import currentThread > > > > class local(object): > > > > ... > >The instance should clear the entry from all the per-thread dictionaries when >it is deallocated, to prevent data from outliving it -- and also to prevent >accidental reuse of the same data by a future instance. > > >Descriptor fun! I think there is a way to write this class so that "regular" >attributes like __class__ still work, and without having to special-case >__dict__. Something along the lines of: > > def __patch(self): > key = "thread-local-%x" % id(self) > d = currentThread().__dict__.setdefault(key, {}) > object.__setattr__(self, '__dict__', d) > > def __getattribute__(self, name): > self.__patch() > return super(local, self).__getattribute__(name) I'm puzzled, is this thread-safe?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4