Thanks to visit codestin.com
Credit goes to github.com

Skip to content

asyncio: __del__() keep reference to warnings.warn #11491

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 2 commits into from
Jan 10, 2019
Merged

asyncio: __del__() keep reference to warnings.warn #11491

merged 2 commits into from
Jan 10, 2019

Conversation

vstinner
Copy link
Member

The del() methods of asyncio classes now keep a strong reference
to the warnings.warn() to be able to display the ResourceWarning
warning in more cases. Ensure that the function remains available if
instances are destroyed late during Python shutdown (while module
symbols are cleared).

The __del__() methods of asyncio classes now keep a strong reference
to the warnings.warn() to be able to display the ResourceWarning
warning in more cases. Ensure that the function remains available if
instances are destroyed late during Python shutdown (while module
symbols are cleared).
@vstinner
Copy link
Member Author

I'm not sure that this change fix a real bug, but I had to make a similar change 2 years ago in the subprocess module, after I modified subprocess to emit ResourceWarning in its destructor: commit 9505b03 to fix https://bugs.python.org/issue29174

commit 9505b03bb0d3c5828115fec9306cb976c43f04d9
Author: Victor Stinner <[email protected]>
Date:   Fri Jan 6 10:44:44 2017 +0100

    Fix subprocess.Popen.__del__() fox Python shutdown
    
    Issue #29174, #26741: subprocess.Popen.__del__() now keeps a strong reference
    to warnings.warn() function.

"_warn" name is a hint that it's not the regular warnings.warn()
function.
Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.
IIRC we discussed a similar change in tulip/asyncio but decided to do nothing.

@vstinner vstinner merged commit fb2c346 into python:master Jan 10, 2019
@vstinner vstinner deleted the asyncio_del branch January 10, 2019 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants