-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-36918: Don't close the object which is again closed by destructor #13317
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
Conversation
| ''') | ||
| try: | ||
| # Silence destructor error | ||
| http.client.HTTPConnection.close = lambda self: None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will affect all instances of HTTPConnection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fakehttp replaces http.client.HTTPConnection with FakeHTTPConnection and unfakehttp restores the old value of http.client.HTTPConnection at the end of test. So I guess it's changing close on FakeHTTPConnection which is generated per test.
https://github.com/python/cpython/pull/13317/files#diff-618652ed25a24a1b635417b4264c9533L101
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @tirkarthi is right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not adding a close() method to FakeHTTPConnection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no test case failures on changing close in FakeHTTPConnection but I haven't had time to analyze it well to see if there are any other cases it affects. So I kept the change minimal to have reported tests silenced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After I wrote a similar change, I now understand this change and I agree that it's correct. But the change is surprising :-) I wrote PR #13996 which adds a "mock_close" attribute to fake_http(): if mock_close is true, a close() method which does nothing is defined. IMHO it's less surprising, since it's more explicitly that only the mock is affected.
|
@asvetlov I would wait since Serhiy had a different opinion on this at https://bugs.python.org/msg342709 |
|
I wrote a simpler change: PR #13955. |
|
Thanks a lot @tirkarthi for proposing this PR and identifying the root cause of these new errors. I merged PR #13996 which is similar (but different :-)) than your PR. |
At the end of test
BytesIOdestructor is called that calls flush and close. Closing the object when the internal counter in FakeSocket gets to zero causes flush to be called on closed object in destructor. Mock the close function and let destructor do the work instead.https://bugs.python.org/issue36918