You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not forget to close all parts after use to free up resources and avoid ResourceWarnings. Framework developers may want to add logic that automatically frees up resources after the request ended.
Zope request does not keep a reference to the MultipartPart, but creates a FormField
so calling MultipartPart.close is not directly applicable, but since what this method does ( code for reference ) is just calling close on the underlying file, calling close on the FileUpload is equivalent.
The fix I'm suggesting is to call close on all FileUploads during HTTPRequest.clear ( I'm sending a pull request doing this ).
The text was updated successfully, but these errors were encountered:
What I did:
Upload a file with an html like this that one:
What I expect to happen:
no warning
What actually happened:
warning on the console:
Very small files do not cause this warning, because a
BytesIO
is usedWhat version of Python and Zope/Addons I am using:
This happens on current Zope master branch.
Suggested fix
Multipart documentation recommends closing
MultipartPart
at the end of request, quoting https://multipart.readthedocs.io/en/latest/usage.html#streaming-parserZope request does not keep a reference to the
MultipartPart
, but creates aFormField
Zope/src/ZPublisher/HTTPRequest.py
Lines 1497 to 1501 in 7802542
which later becomes a
FileUpload
Zope/src/ZPublisher/HTTPRequest.py
Lines 547 to 550 in 7802542
so calling
MultipartPart.close
is not directly applicable, but since what this method does ( code for reference ) is just callingclose
on the underlying file, callingclose
on theFileUpload
is equivalent.The fix I'm suggesting is to call
close
on allFileUpload
s duringHTTPRequest.clear
( I'm sending a pull request doing this ).The text was updated successfully, but these errors were encountered: