From 946fd7e2c5405d1fd080469de5616214722faad0 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Tue, 10 Apr 2018 17:48:59 +0800 Subject: [PATCH] close the old body explicitly after seek() --- smart_open/s3.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/smart_open/s3.py b/smart_open/s3.py index ae401896..3dc2fdf6 100644 --- a/smart_open/s3.py +++ b/smart_open/s3.py @@ -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.