<s> """<STR_LIT>""" <EOL> import gc <EOL> from ants import signals <EOL> from ants . utils . exceptions import NotConfigured <EOL> from ants . utils . trackref import live_refs <EOL> class MemoryDebugger ( object ) : <EOL> def __init__ ( self , stats ) : <EOL> self . stats = stats <EOL> @ classmethod <EOL> def from_crawler ( cls , crawler ) : <EOL> if not crawler . settings . getbool ( '<STR_LIT>' ) : <EOL> raise NotConfigured <EOL> o = cls ( crawler . stats ) <EOL> crawler . signals . connect ( o . spider_closed , signal = signals . spider_closed ) <EOL> return o <EOL> def spider_closed ( self , spider , reason ) : <EOL> gc . collect ( ) <EOL> self . stats . set_value ( '<STR_LIT>' , len ( gc . garbage ) , spider = spider ) <EOL> for cls , wdict in live_refs . iteritems ( ) : <EOL> if not wdict : <EOL> continue <EOL> self . stats . set_value ( '<STR_LIT>' % cls . __name__ , len ( wdict ) , spider = spider ) </s>
