From 5448268d5ce153c1c7437da07ace7afe74750191 Mon Sep 17 00:00:00 2001 From: ClosedPort22 <44864697+ClosedPort22@users.noreply.github.com> Date: Tue, 8 Aug 2023 23:33:03 +0800 Subject: [PATCH] [downloader:http] close connection when file already exists (#3748) --- gallery_dl/downloader/http.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index 4ec03983cb..30ac0016b8 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -225,6 +225,14 @@ def _download_impl(self, url, pathfmt): pathfmt.build_path() if pathfmt.exists(): pathfmt.temppath = "" + # release the connection back to pool by explicitly + # calling .close() + # see https://requests.readthedocs.io/en/latest/user + # /advanced/#body-content-workflow + # when the image size is on the order of megabytes, + # re-establishing a TLS connection will typically be faster + # than consuming the whole response + response.close() return True if self.part and metadata: pathfmt.part_enable(self.partdir) @@ -246,6 +254,7 @@ def _download_impl(self, url, pathfmt): if self._adjust_extension(pathfmt, file_header) and \ pathfmt.exists(): pathfmt.temppath = "" + response.close() return True # set open mode