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'>")
"""
通过gc.get_objects()检查当前运行的各对象数量
最新推荐文章于 2024-07-16 15:00:42 发布