SheffieldML / SheffieldML/GPy

ResourceWarning From Unclosed Files

Open
#950 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
570
PR merge metrics
No merged PRs in 30d

Description

I've been getting the following warning message when using GPy. (It actually doesn't occur upon import, and I don't know exactly when it occurs.)

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/GPy/util/config.py:35: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/GPy/defaults.cfg' mode='r' encoding='UTF-8'> config.readfp(open(default_file)) ResourceWarning: Enable tracemalloc to get the object allocation traceback /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/GPy/util/datasets.py:58: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/GPy/util/data_resources.json' mode='r' encoding='utf-8'> json_data = open(path, encoding='utf-8').read() ResourceWarning: Enable tracemalloc to get the object allocation traceback /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/GPy/util/datasets.py:63: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/GPy/util/football_teams.json' mode='r' encoding='utf-8'> json_data = open(path, encoding='utf-8').read() ResourceWarning: Enable tracemalloc to get the object allocation traceback

This seems to result from a few files (in GPy/util/dataset.py and GPy/util/config.py) that are opened and not closed. I've fixed it by replacing the relevant "open" statements with "with open". Please let me know if I should make a pull request with this change.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read GPy/util/config.py and GPy/util/datasets.py, focusing on the open calls identified in the warning messages. Reproduce the reported ResourceWarning and verify that the affected files are closed after the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.