<s> from testing_helpers import test_gc <EOL> unordered_finalize = { } <EOL> class ObjWithFinalizer ( object ) : <EOL> def __init__ ( self , index ) : <EOL> self . index = index <EOL> def __del__ ( self ) : <EOL> unordered_finalize [ self . index ] = True <EOL> class ObjWithFinalizerAndRef ( object ) : <EOL> def __init__ ( self , index , append_list ) : <EOL> self . index = index <EOL> self . ref = None <EOL> self . append_list = append_list <EOL> def __del__ ( self ) : <EOL> self . append_list . append ( self . index ) <EOL> def scope1 ( ) : <EOL> objs1 = [ ObjWithFinalizer ( i ) for i in xrange ( <NUM_LIT:20> ) ] <EOL> items_in_list = <NUM_LIT:8> <EOL> number_of_attempts = <NUM_LIT:10> <EOL> def scope2 ( ) : <EOL> increasing_lists = [ ] <EOL> for _ in xrange ( number_of_attempts ) : <EOL> increasing_list = [ ] <EOL> increasing_lists . append ( increasing_list ) <EOL> objs = [ ObjWithFinalizerAndRef ( i , increasing_list ) for i in xrange ( items_in_list ) ] <EOL> for i in xrange ( items_in_list - <NUM_LIT:1> ) : <EOL> objs [ i ] . ref = objs [ i + <NUM_LIT:1> ] <EOL> return increasing_lists <EOL> def scope3 ( ) : <EOL> decreasing_lists = [ ] <EOL> for _ in xrange ( number_of_attempts ) : <EOL> decreasing_list = [ ] <EOL> decreasing_lists . append ( decreasing_list ) <EOL> objs = [ ObjWithFinalizerAndRef ( i , decreasing_list ) for i in xrange ( items_in_list ) ] <EOL> for i in xrange ( items_in_list - <NUM_LIT:1> ) : <EOL> objs [ i + <NUM_LIT:1> ] . ref = objs [ i ] <EOL> return decreasing_lists <EOL> test_gc ( scope1 ) <EOL> print sorted ( unordered_finalize . keys ( ) ) <EOL> increasing_lists = test_gc ( scope2 , <NUM_LIT> ) <EOL> decreasing_lists = test_gc ( scope3 , <NUM_LIT> ) <EOL> for increasing_list in increasing_lists : <EOL> if increasing_list == range ( items_in_list ) : <EOL> print "<STR_LIT>" <EOL> print increasing_list <EOL> print "<STR_LIT>" <EOL> break <EOL> for decreasing_list in decreasing_lists : <EOL> decreasing_list . reverse ( ) <EOL> if decreasing_list == range ( items_in_list ) : <EOL> print "<STR_LIT>" <EOL> print decreasing_list <EOL> print "<STR_LIT>" <EOL> break </s>
