python的bug,直到3.2还有:threading.local不释放成员属性,所以如果threading.local实例里引用了threading.local的实例,就不在释放了。
http://bugs.python.org/issue3757 threading.local doesn't support cyclic garbage collecting
http://bugs.python.org/issue1868 threading.local doesn't free attrs when assigning thread exits
重现例子:
#!/usr/bin/env python2.6
# coding: utf-8
from threading import local
class Client(local):
def __init__(self):
self.host = self
print ('init')
def __del__( self ):
print ('del')
for ii in range( 3 ):
mc = Client()
# uncomment following line to let __del__ to be called.
# mc.host = None