Skip to content

Make http.MediaFileUpload close its file descriptor.#600

Merged
tseaver merged 2 commits into
googleapis:masterfrom
wangxf123456:close-mediafileupload-fd
Jul 17, 2019
Merged

Make http.MediaFileUpload close its file descriptor.#600
tseaver merged 2 commits into
googleapis:masterfrom
wangxf123456:close-mediafileupload-fd

Conversation

@wangxf123456
Copy link
Copy Markdown
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
Copy Markdown
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()

Comment thread googleapiclient/http.py Outdated
"""
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
Copy Markdown
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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