Dont perform implicit close/warning on __del__
#2026
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We currently attempt to perform a bit of hand-holding for cases where a client instance has not been closed at the point it is deleted. The reasoning here was to try to give users a bit more of a guard against unintentional resource leaks.
Our behaviour here was...
.close()
clients on__del__
, if they're still open.__del__
, if they're still open.As it turns out, this just isn't reliable. We really can't do this properly, because if
__del__
is called atatexit
then there's all sorted of bit of stdlib that may not be available. We can't reliably call intowarnings.warn
, and it turns out we can't even reliably access the properties on anintenum
class. Geez.So. Let's just not do this anymore.
If you're leaking client instances (which as it happens, zillions of
requests
andurllib3
using codebases currently already do.) Then okay, that's just the way it is. I'm not sure what flags you'd need to enable in python to have the system warn you about when that's the case, but we should rely on that level of warning, rather than attempting to add any ourselves.Better that we stick with the current status-quo, than attempt to do better and actually just end up with user-hostile exceptions or undefined behaviours.