Describe the bug
Unclosed file leaks causing a resource warning.
|
return yaml.safe_load(open(inferred_file_path, "r")) |
Discovered this when running a test suite that uses sagemaker and has warnings enabled. It's an actual bug since a user will end up with a open config file that's never closed which can case all kinds of weird behaviors.
To reproduce
A clear, step-by-step set of instructions to reproduce the bug.
The provided code need to be complete and runnable, if additional data is needed, please include them in the issue.
python -X dev -X tracemalloc=20 -m pytest ./tests/unit/sagemaker/config -W error
E Traceback (most recent call last):
E File "C:\Users\xxx\.venv\Lib\site-packages\sagemaker\config\config.py", line 184, in _load_config_from_file
E return yaml.safe_load(open(inferred_file_path, "r"))
E ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E ResourceWarning: unclosed file <_io.TextIOWrapper name='C:\\Users\\xxx\\.sagemaker\\config.yaml' mode='r' encoding='cp1252'>
Expected behavior
Close the file properly, use a with statement.
Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.
System information
A description of your system. Please provide:
- SageMaker Python SDK version: master
- Framework name (eg. PyTorch) or algorithm (eg. KMeans): n/a
- Framework version: n/a
- Python version: 3.11
- CPU or GPU: cpu
- Custom Docker image (Y/N): n/a
Additional context
Add any other context about the problem here.
Describe the bug
Unclosed file leaks causing a resource warning.
sagemaker-python-sdk/src/sagemaker/config/config.py
Line 184 in c799d1a
Discovered this when running a test suite that uses sagemaker and has warnings enabled. It's an actual bug since a user will end up with a open config file that's never closed which can case all kinds of weird behaviors.
To reproduce
A clear, step-by-step set of instructions to reproduce the bug.
The provided code need to be complete and runnable, if additional data is needed, please include them in the issue.
Expected behavior
Close the file properly, use a with statement.
Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.
System information
A description of your system. Please provide:
Additional context
Add any other context about the problem here.