msg230901 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2014-11-09 19:22 |
Here is large patch which convert a code which potentially can leak file descriptor to use the with statement so files are always closed. This can make effect mainly on alternative Python implementation without reference counting. But even on CPython this will get rid from resource leaking warnings. |
|
|
msg238602 - (view) |
Author: Berker Peksag (berker.peksag) *  |
Date: 2015-03-20 03:30 |
Looks good. A couple of comments: * Doc/includes/email-* changes have already been committed. * There is a commented-out line in Tools/scripts/nm2def.py: - f.close() + # f.close() * The patch is huge, I'd commit Tools/ and Lib/test/ parts separately. * Most of the open(..., 'r') usages can be changed to open(...) * It would be good to add context management protocol support to http.client.HTTPConnection. |
|
|
msg238625 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2015-03-20 09:12 |
fd_leaks.diff is impossible to review, even Rietveld gave up, it's too big :-p Could you please your patch into smaller patches? Split by directory for example. |
|
|
msg238627 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2015-03-20 09:20 |
Posting a version of Serhiy’s patch made with “hg diff -p --ignore-all-space”. It is a bit shorter, and should not include all the re-indented lines, which may help reviewing. |
|
|
msg238643 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-03-20 11:03 |
The patch is synchronized with the tip and divided on smaller parts. > There is a commented-out line in Tools/scripts/nm2def.py: It is in a pair to commented out open() two lines above. > Most of the open(..., 'r') usages can be changed to open(...) Done. > * It would be good to add context management protocol support to > http.client.HTTPConnection. In separate issue. |
|
|
msg238655 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2015-03-20 12:36 |
There were a couple mistakes I found; see Reitveld. I was going to say to leave the open(mode="r") parameter as it is, since an explicit "r" is more readable, but since you already took some out, I’m not going to complain. While many of the changes look worthwhile, I do worry that some of them will never be tested (at least until say Python 3.14 or something). E.g. I just tried running Tools/scripts/dutree.py cos it looked interesting, but was confronted with the “unorderable types: int() < NoneType()” Python 2-ism. |
|
|
msg238670 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-03-20 13:39 |
Here are updated patches with fixed mistakes found by Martin. > While many of the changes look worthwhile, I do worry that some of them will > never be tested (at least until say Python 3.14 or something). E.g. I just > tried running Tools/scripts/dutree.py cos it looked interesting, but was > confronted with the “unorderable types: int() < NoneType()” Python 2-ism. Yes, sad, but Tools/scripts/ is full of Python 2-isms. |
|
|
msg238671 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-03-20 13:39 |
п'ятниця, 20-бер-2015 12:36:25 ви написали: > Martin Panter added the comment: > > There were a couple mistakes I found; see Reitveld. I was going to say to > leave the open(mode="r") parameter as it is, since an explicit "r" is more > readable, but since you already took some out, I’m not going to complain. > > While many of the changes look worthwhile, I do worry that some of them will > never be tested (at least until say Python 3.14 or something). E.g. I just > tried running Tools/scripts/dutree.py cos it looked interesting, but was > confronted with the “unorderable types: int() < NoneType()” Python 2-ism. > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue22831> > _______________________________________ |
|
|
msg238898 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2015-03-22 13:55 |
The new fd_leaks_tools1_2.patch seems to have dropped the changes for Tools/scripts/treesync.py, compared to the previous fd_leaks_tools1.patch. |
|
|
msg238901 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2015-03-22 14:23 |
Oh, I forgot to publish my comments. I dropped the changes for treesync.py because treesync.py is not work with Python 3. I have written separate patch for it and will open separate issue after writing tests. |
|
|
msg240050 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2015-04-04 08:03 |
New changeset ea94f6c87f5d by Serhiy Storchaka in branch 'default': Issue #22831: Use "with" to avoid possible fd leaks. https://hg.python.org/cpython/rev/ea94f6c87f5d |
|
|
msg257400 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
Date: 2016-01-03 06:37 |
Serhiy, what's the status of this? |
|
|
msg257402 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2016-01-03 07:00 |
Only the most important patch for the stdlib was committed. Patches for distutils, tests and tools are not committed still. fd_leaks_distutils.patch fd_leaks_tools1_2.patch fd_leaks_tools2_2.patch fd_leaks_tests1_2.patch fd_leaks_tests2_2.patch |
|
|
msg257587 - (view) |
Author: Martin Panter (martin.panter) *  |
Date: 2016-01-06 05:43 |
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. |
|
|
msg331130 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-12-05 15:14 |
PR 10921 is based on fd_leaks_distutils.patch. |
|
|
msg331134 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-12-05 16:07 |
PR 10926 is based on fd_leaks_tools1_2.patch. PR 10927 is based on fd_leaks_tools2_2.patch. PR 10928 is based on fd_leaks_tests1_2.patch. PR 10929 is based on fd_leaks_tests2_2.patch. Some of changes in these patches were already applied in other issues. |
|
|
msg331137 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-12-05 17:12 |
self.addCleanup(f.close) can not be used if the same file should be opened several times in the test. It can not be used also if the file is deleted in the test or in tearDown(). |
|
|
msg332193 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-12-20 07:50 |
Éric, could you please take a look at PR 10921? |
|
|
msg332240 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-12-20 17:00 |
New changeset c5d5dfdb223efb0e668e3f317d31b8b70ae96aa6 by Serhiy Storchaka in branch 'master': bpo-22831: Use "with" to avoid possible fd leaks in distutils. (GH-10921) https://github.com/python/cpython/commit/c5d5dfdb223efb0e668e3f317d31b8b70ae96aa6 |
|
|
msg337169 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-03-05 08:06 |
New changeset 9e4861f52349011cd5916eef8e8344575e8ac426 by Serhiy Storchaka in branch 'master': bpo-22831: Use "with" to avoid possible fd leaks in tests (part 1). (GH-10928) https://github.com/python/cpython/commit/9e4861f52349011cd5916eef8e8344575e8ac426 |
|
|
msg337170 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-03-05 08:06 |
New changeset 5b10b9824780b2181158902067912ee9e7b04657 by Serhiy Storchaka in branch 'master': bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929) https://github.com/python/cpython/commit/5b10b9824780b2181158902067912ee9e7b04657 |
|
|
msg339179 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-03-30 06:32 |
New changeset afbb7a371fb44edc731344eab5b474ad8f7b57d7 by Serhiy Storchaka in branch 'master': bpo-22831: Use "with" to avoid possible fd leaks in tools (part 1). (GH-10926) https://github.com/python/cpython/commit/afbb7a371fb44edc731344eab5b474ad8f7b57d7 |
|
|
msg339180 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-03-30 06:33 |
New changeset 172bb39452ae8b3ccdf5d1f23ead46f44200cd49 by Serhiy Storchaka in branch 'master': bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927) https://github.com/python/cpython/commit/172bb39452ae8b3ccdf5d1f23ead46f44200cd49 |
|
|