Index: release25-maint/Lib/_threading_local.py =================================================================== --- release25-maint/Lib/_threading_local.py (revision 60064) +++ release25-maint/Lib/_threading_local.py (working copy) @@ -130,6 +130,26 @@ >>> mydata.number 11 +Attributes on a local are cleaned up when the assigning thread finishes: + + >>> import weakref + >>> mydata = threading.local() + + >>> class SomeObj(object): + ... instances=weakref.WeakValueDictionary() + ... def __init__(self): + ... self.instances[id(self)]=self + + >>> def doit(): + ... mydata.x=SomeObj() + + >>> t=threading.Thread(target=doit) + >>> t.start() + >>> t.join() + >>> del t + >>> SomeObj.instances.values() + [] + >>> del mydata """