Skip to content

Commit

Permalink
close the old body explicitly after seek()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang Yang committed Apr 10, 2018
1 parent 925634f commit 946fd7e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions smart_open/s3.py
Expand Up @@ -114,6 +114,16 @@ def seek(self, position):
self._position = position
range_string = _range_string(self._position)
logger.debug('content_length: %r range_string: %r', self._content_length, range_string)

#
# Close old body explicitly.
# When first seek(), self._body is not exist. Catch the exception and do nothing.
#
try:
self._body.close()
except AttributeError as e:
pass

if position == self._content_length == 0 or position == self._content_length:
#
# When reading, we can't seek to the first byte of an empty file.
Expand Down

0 comments on commit 946fd7e

Please sign in to comment.