gc를 통과하다.get_objects () 현재 실행 중인 대상 수량 검사

1604 단어
stats = []
objects = gc.get_objects()

objects_temp = objects[100:120]
print('objects:', objects_temp)

run_objects = {}
run_others = {}
for o in objects:
    if hasattr(o, '__class__'):
        key = str(o.__class__)
        run_list = run_objects
    else:
        key = type(o)
        run_list = run_others

    if key in run_list:
        run_list[key] += 1
    else:
        run_list[key] = 1

for obj in run_objects:
    print('object', run_objects[obj], obj)
    stats.append([run_objects[obj], obj])

for obj in run_others:
    print('none object', run_others[obj], obj)
    stats.append([run_others[obj], obj])

"""
('object', 4, "<type 'zipimporter'>")
('object', 1, "<type 'NotImplemented'>")
('object', 1, "<class 'float_info'>")
('object', 3, "<class 'site._Printer'>")
('object', 5, "<type 'frame'>")
('object', 64, "<type 'weakref'>")
('object', 109, "<type 'set'>")
('object', 2583, "<type 'builtin-code'>")
('object', 6, "<type 'SRE_Pattern'>")
('object', 48, "<class '_weakrefset.WeakSet'>")
('object', 1361, "<type 'tuple'>")
('object', 25, "<type 'classmethod'>")
('object', 18, "<type 'method'>")
"""

좋은 웹페이지 즐겨찾기