/usr/lib/python2.7/dist-packages/dipy/testing/memory.py is in python-dipy 0.10.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import gc
from collections import defaultdict
def get_type_refcount(pattern=None):
"""
Retrieves refcount of types for which their name matches `pattern`.
Parameters
----------
pattern : str
Consider only types that have `pattern` in their name.
Returns
-------
dict
The key is the type name and the value is the refcount.
"""
gc.collect()
refcounts_per_type = defaultdict(int)
for obj in gc.get_objects():
obj_type_name = type(obj).__name__
# If `pattern` is not None, keep only matching types.
if pattern is None or pattern in obj_type_name:
refcounts_per_type[obj_type_name] += 1
return refcounts_per_type
|