python-zeep icon indicating copy to clipboard operation
python-zeep copied to clipboard

Properly close 'file://' resources

Open CharString opened this issue 2 years ago • 0 comments

I bumped into this when opening several wsdl which in turn opened lots of xsd, with 'file://' scheme.

The issue was that the resp.raw.close nor resp.raw.release_conn set in the FileAdapter were ever called.

It's unclear to me whether this should be fixed in requests. It doesn't do that great a job at resource management for the naive user aka Human™. It makes sense to me that exhaustively reading Response.raw should close it unless the caller explicitly set stream on the request. Probably by using this closing pattern in the generator in Response.iter_content.

Workarounds without this fix:

  • using a scheme-less url as zeep will assume it's a local path and open the file as a context manager.
  • use one of the caches from zeep.cache to hide duplicate open resources.

CharString avatar Sep 15 '23 15:09 CharString