bpo-29564: warnings suggests to enable tracemalloc by vstinner · Pull Request #10486 · python/cpython (original) (raw)

For some reason, I expected that thefe's an optimizations for modules already found in cache, hence that respective file descriptors would not be duplicated needlessly. I was wrong, as fortunately Python can figure out on its own these days, and moreover is capable to indicate precisely where the problem occurred.

Initial messages (./run-tests filter):

/clufter/format.py:807: ResourceWarning: unclosed file <_io.TextIOWrapper name='/clufter/tests/XMLFormat-walk/cluster/quorumd/heuristic.py' mode='r' encoding='utf-8'> mfile, mpath, mdesc = find_module(name, [root]) ResourceWarning: Enable tracemalloc to get the object allocation traceback /clufter/filter.py:1066: ResourceWarning: unclosed file <_io.TextIOWrapper name='/clufter/tests/XMLFormat-walk/cluster/rm/failoverdomains/failoverdomain.py' mode='r' encoding='utf-8'> walk = in_obj.walk_schema(root_dir, preprocess=cls._xslt_preprocess, ResourceWarning: Enable tracemalloc to get the object allocation traceback

Sample message when tracemalloc enabled:

Object allocated at (most recent call last): File "/usr/lib64/python3.8/runpy.py", lineno 192 return _run_code(code, main_globals, None, [14 frames skipped] File "/clufter/tests/filter.py", lineno 66 r = flt.get_template(in_obj, symbol='direct_xslt_test', File "/clufter/filter.py", lineno 1066 walk = in_obj.walk_schema(root_dir, preprocess=cls._xslt_preprocess, File "/clufter/format.py", lineno 807 mfile, mpath, mdesc = find_module(name, [root]) File "/usr/lib64/python3.8/imp.py", lineno 302 file = open(file_path, mode, encoding=encoding)

References: https://docs.python.org/3/whatsnew/3.6.html#warnings python/cpython#10486

Signed-off-by: Jan Pokorný jpokorny@redhat.com