[Python-Dev] Version 3 Proposal: thread-local data (original) (raw)

Samuele Pedroni pedronis at bluewin.ch
Thu Jul 1 06:30:55 EDT 2004


At 16:53 30.06.2004 -0400, Jim Fulton wrote:

def patch(self): key = object.getattribute(self, 'local_key') d = currentThread().dict.get(key) if d is None: d = {} currentThread().dict[key] = d object.setattr(self, 'dict', d)

# we have a new instance dict, so call out init if we have # one cls = type(self) if cls.init is not object.init: args, kw = object.getattribute(self, 'local_args') cls.init(self, *args, **kw) else: object.setattr(self, 'dict', d) class local(localbase): def getattribute(self, name): patch(self)

what happens if there's a thread switch, to another thread using the local object, here? between patching dict and accessing dict

return object.getattribute(self, name)

def setattr(self, name, value): patch(self) return object.setattr(self, name, value) def delattr(self, name): patch(self) return object.delattr(self, name) def del(self): key = object.getattribute(self, 'local_key') for thread in enumerate(): if key in thread.dict: del thread.dict[key] Any objections? Any more tricks up your sleeve Armin? :) Jim -- Jim Fulton mailto:jim at zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/pedronis%40bluewin.ch



More information about the Python-Dev mailing list