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

Tim Peters tim.one at comcast.net
Thu Jul 1 00:12:27 EDT 2004


[Jim] ...

def del(self): key = object.getattribute(self, 'local_key') for thread in enumerate(): if key in thread.dict: del thread.dict[key]

Note that a del method should never reference a module global "enumerate" in this case) -- it's all but certain to lead to "iteration over non-sequence" Mystery Errors at Python shutdown time (due to module globals getting "None'd out"). The conventional workaround is to give the class an attribute initialized from the module global; e.g.,

class local(_localbase): _enumerate = threading.enumerate

...

def __del__(self):
    ...
    for thread in self._enumerate():

The conventional workaround that doesn't work is to spell that

    for thread in local._enumerate():

instead; it doesn't work because "local" is also a module global.



More information about the Python-Dev mailing list