ResourceWarning From Unclosed Files
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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