Over a million developers have joined DZone.

Mollified About ResourceWarnings

DZone's Guide to

Mollified About ResourceWarnings

Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

Last month I griped about ResourceWarnings in Python 3, arguing they’re a useless irritation in a language that can clean up resources automatically. Python core developer Nick Coghlan responded in the comments and I understand the choice now.

Nick explains that ResourceWarnings reveal problems that would make the Python standard library inefficient running in PyPy. A resource like a socket can clean itself up promptly in CPython, but now that it issues a ResourceWarning when it isn’t explicitly closed, the socket helps library authors prepare for PyPy, in which resources are not promptly cleaned up. If I decide that lazy cleanup is ok, I can avoid ResourceWarnings by using a weakref callback to close the resource before it’s deleted, whenever that happens.

Nick also pointed out that ResourceWarnings are off by default in normal Python programs—I just saw them all the time because I usually run my code in nosetest.

Read our full discussion in the comments.

Props to Nick for taking the time to explain.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.


Published at DZone with permission of A. Jesse Jiryu Davis, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}