[issue22831] Use "with" to avoid possible fd leaks

Martin Panter report at bugs.python.org
Wed Jan 6 00:43:33 EST 2016


Martin Panter added the comment:

I had another look at the five patches you mentioned. I made a couple review comments about expanding the scope of some “with” statements.

There are a couple changes that add explicit file closing, where it was previously up to the garbage collector. I.e. code like open(...).read(). I think those changes are the most important, although they are scattered over the various patches.

On the other hand, some of the changes in the test suite, particularly test_dbm_dumb.py and test_xmlrpc.py, hardly seem worth it. The main benefit of the “with” statement would be if the test code fails, which hopefully won’t happen that often. :)

In the test suite, perhaps it would be better to call self.addCleanup(f.close) or similar in many cases. That way you wouldn’t need contextlib.closing() as much, and there would be less file history clutter and “cavern code”, due to the extra indentation.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22831>
_______________________________________


More information about the Python-bugs-list mailing list