New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unclosed file warning when reading a python config module #1889

Merged
merged 2 commits into from Oct 2, 2018

Conversation

Projects
None yet
2 participants
@lopopolo
Copy link
Contributor

lopopolo commented Oct 2, 2018

The raw open call in _compat:execfile_ did not close the file handle.
Switch to using pathlib to read the raw bytes.

Logs:

Oct 02 05:04:38 ubuntu-bionic systemd[1]: Started Gunicorn server for hyperbola django.
Oct 02 05:04:38 ubuntu-bionic gunicorn[12173]: /hyperbola/app/releases/20181002050352/venv/lib/python3.6/site-packages/gunicorn/_compat.py:71: ResourceWarning: unclosed file <_io.BufferedReader name='/hyperbola/app/current/gunicorn.py'>
Oct 02 05:04:38 ubuntu-bionic gunicorn[12173]:   code = compile(open(fname, 'rb').read(), fname, 'exec')
Oct 02 05:04:38 ubuntu-bionic gunicorn[12173]: [2018-10-02 05:04:38 +0000] [12173] [INFO] Starting gunicorn 19.9.0
Oct 02 05:04:38 ubuntu-bionic gunicorn[12173]: [2018-10-02 05:04:38 +0000] [12173] [INFO] Listening at: unix:/var/run/hyperbola-local/hyperbola.sock (12173)

I am running gunicorn 19.9.0 and tested my fix by patching my virtualenv.

lopopolo added some commits Oct 2, 2018

Fix unclosed file warning when reading a python config module
The raw open call in _compat:execfile_ did not close the file handle.
Switch to using pathlib to read the raw bytes.
@lopopolo

This comment has been minimized.

Copy link
Contributor

lopopolo commented Oct 2, 2018

It looks like Path.read_bytes was introduced in Python 3.5.

I've put up a new patch that uses a with context block. :)

@lopopolo

This comment has been minimized.

Copy link
Contributor

lopopolo commented Oct 2, 2018

FWIW I spotted this by launching gunicorn with the env variable PYTHONWARNINGS=all

@berkerpeksag berkerpeksag merged commit eae3ef0 into benoitc:master Oct 2, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@berkerpeksag

This comment has been minimized.

Copy link
Collaborator

berkerpeksag commented Oct 2, 2018

Good catch, thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment