Skip to content

Rebased elnuno's fix and retested: "Close CallbackFileWrapper.__buf once it's used." #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cachecontrol/filewrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ def _close(self):
# and allows the garbage collector to do it's thing normally.
self.__callback = None

# Closing the BytesIO stream releases memory. Important when caching
# big files.
self.__buf.close()

def read(self, amt=None):
data = self.__fp.read(amt)
self.__buf.write(data)
if data:
# We may be dealing with b'', a sign that things are over:
# it's passed e.g. after we've already closed self.__buf.
self.__buf.write(data)
if self.__is_fp_closed():
self._close()

Expand Down