#NEWLINE# def stats( self ) : #NEWLINE# #INDENT# output = [ 'Statistics:' ] #NEWLINE# for trial in range ( 10 ) : #NEWLINE# #INDENT# if ( request_counter . count > 0 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# time . sleep ( 0.5 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output . append ( '\nNot all requests closed properly.' ) #NEWLINE# #UNINDENT# gc . collect ( ) #NEWLINE# gc . collect ( ) #NEWLINE# unreachable = gc . collect ( ) #NEWLINE# if unreachable : #NEWLINE# #INDENT# if ( objgraph is not None ) : #NEWLINE# #INDENT# final = objgraph . by_type ( 'Nondestructible' ) #NEWLINE# if final : #NEWLINE# #INDENT# objgraph . show_backrefs ( final , filename = 'finalizers.png' ) #NEWLINE# #UNINDENT# #UNINDENT# trash = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for x in gc . garbage : #NEWLINE# #INDENT# trash [ type ( x ) ] = ( trash . get ( type ( x ) , 0 ) + 1 ) #NEWLINE# #UNINDENT# if trash : #NEWLINE# #INDENT# output . insert ( 0 , ( '\n%s unreachable objects:' % unreachable ) ) #NEWLINE# trash = [ ( v , tree ) for ( k , v ) in trash . items ( ) ] #NEWLINE# trash . sort ( ) #NEWLINE# for pair in trash : #NEWLINE# #INDENT# output . append ( ( '    ' + repr ( pair ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# allobjs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( cls , minobj , maxobj , msg ) in self . classes : #NEWLINE# #INDENT# allobjs [ cls ] = get_instances ( cls ) #NEWLINE# #UNINDENT# for ( cls , minobj , maxobj , msg ) in self . classes : #NEWLINE# #INDENT# objs = allobjs [ cls ] #NEWLINE# lenobj = len ( objs ) #NEWLINE# if ( ( lenobj < minobj ) or ( lenobj > maxobj ) ) : #NEWLINE# #INDENT# if ( minobj == maxobj ) : #NEWLINE# #INDENT# output . append ( ( '\nExpected %s %r references, got %s.' % ( minobj , cls , lenobj ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output . append ( ( '\nExpected %s to %s %r references, got %s.' % ( minobj , maxobj , cls , lenobj ) ) ) #NEWLINE# #UNINDENT# for obj in objs : #NEWLINE# #INDENT# if ( objgraph is not None ) : #NEWLINE# #INDENT# ig = [ id ( objs ) , id ( inspect . currentframe ( ) ) ] #NEWLINE# fname = ( 'graph_%s_%s.png' % ( cls . __name__ , id ( obj ) ) ) #NEWLINE# objgraph . show_backrefs ( obj , extra_ignore = ig , max_depth = 4 , too_many = 20 , filename = fname , extra_info = get_context ) #NEWLINE# #UNINDENT# output . append ( ( '\nReferrers for %s (refcount=%s):' % ( repr ( obj ) , sys . getrefcount ( obj ) ) ) ) #NEWLINE# t = ReferrerTree ( ignore = [ objs ] , maxdepth = 3 ) #NEWLINE# tree = t . ascend ( obj ) #NEWLINE# output . extend ( t . format ( tree ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return '\n' . join ( output )