Re: [Python-Dev] Version 3 Proposal: thread-local data
[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.
participants (1)
-
Tim Peters