Skip to content

Commit 79215a3

Browse files
committed
Clean leaking file descriptors. Eliminates ResourceWarnings.
1 parent b049964 commit 79215a3

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ onwards Python 3.4 and later are also supported.
1515

1616
Fixed:
1717

18+
- issue2551161 - Fix ResourceWarnings when running with -W default.
19+
Cleaned up leaking file descriptors from zopetal pre-compile, python
20+
module compile and loading localization file. (John Rouillard)
21+
1822
Features:
1923

2024
- issue2551147 - Enable compression of http responses in roundup.

roundup/cgi/engine_zopetal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def load(self, tplname):
4242
pt = RoundupPageTemplate()
4343
# use pt_edit so we can pass the content_type guess too
4444
content_type = mimetypes.guess_type(filename)[0] or 'text/html'
45-
pt.pt_edit(open(src).read(), content_type)
45+
with open(src) as srcd:
46+
pt.pt_edit(srcd.read(), content_type)
4647
pt.id = filename
4748
pt.mtime = stime
4849
# Add it to the cache. We cannot do this until the template

roundup/i18n.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def get_translation(language=None, tracker_home=None,
194194
# note: current implementation of gettext_module
195195
# always adds fallback to the end of the fallback chain.
196196
translator.add_fallback(translation_class(mo))
197+
mo.close()
197198
except IOError:
198199
# ignore unreadable .mo files
199200
pass

roundup/instance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def nuke(self):
218218

219219
def _compile(self, fname):
220220
fname = os.path.join(self.tracker_home, fname)
221-
return compile(builtins.open(fname).read(), fname, 'exec')
221+
with builtins.open(fname) as fnamed:
222+
return compile(fnamed.read(), fname, 'exec')
222223

223224
def _exec(self, obj, env):
224225
if self.libdir:

0 commit comments

Comments
 (0)