Skip to content

Commit

Permalink
Сlose the old body explicitly after seek for S3. Fix #187 (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
inksink authored and menshikh-iv committed Apr 10, 2018
1 parent 925634f commit 5b58023
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions smart_open/s3.py
Original file line number Diff line number Diff line change
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 5b58023

Please sign in to comment.