Skip to content
New issue

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

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

Already on GitHub? # to your account

Make http.MediaFileUpload close its file descriptor. #600

Merged
merged 2 commits into from
Jul 17, 2019

Conversation

wangxf123456
Copy link
Contributor

Fixes #575

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Dec 7, 2018
@sduskis sduskis requested a review from a team December 7, 2018 03:52
Copy link
Contributor

@tseaver tseaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch! In addition to my comment inline, can you please add a testcase in tests/test_http.py which exercises the new code? Something like:

class TestMediaUpload(unittest.TestCase):
...
  def test_media_file_upload_closes_fd_in___del__(self):
    file_desc = mock.Mock(spec=['close'])
    opener = mock.mock_open(file_desc)
    with mock.patch('googleapis.http.open', opener):
      upload = MediaFileUpload(datafile('test_close'))
    self.assertIs(upload.stream(), file_desc)
    del upload
    file_desc.close.assert_called_once_with()

@@ -551,16 +551,20 @@ def __init__(self, filename, mimetype=None, chunksize=DEFAULT_CHUNK_SIZE,
in a single request.
"""
self._filename = filename
fd = open(self._filename, 'rb')
self._fd = open(self._filename, 'rb')

This comment was marked as spam.

This comment was marked as spam.

@wangxf123456
Copy link
Contributor Author

Thanks very much for your review!

@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Feb 7, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Feb 7, 2019
@yoshi-automation yoshi-automation removed the 🚨 This issue needs some love. label Jul 3, 2019
@busunkim96 busunkim96 requested a review from tseaver July 17, 2019 00:05
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Receive warnings "ResourceWarning: unclosed file" when using googleapiclient.http.MediaFileUpload
6 participants