Merge ~cjwatson/txpkgupload:py3-close-log-file into txpkgupload:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: bbf3c6f71565a6f9a085347e3d6dc6224f5ad51c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/txpkgupload:py3-close-log-file
Merge into: txpkgupload:master
Diff against target: 54 lines (+11/-3)
2 files modified
src/txpkgupload/services.py (+10/-3)
src/txpkgupload/tests/test_plugin.py (+1/-0)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+393262@code.launchpad.net

Commit message

Silence ResourceWarnings due to an open log file

Description of the change

We need to explicitly close the service's log file if we opened one.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/txpkgupload/services.py b/src/txpkgupload/services.py
2index 89e9e4d..613ff30 100644
3--- a/src/txpkgupload/services.py
4+++ b/src/txpkgupload/services.py
5@@ -63,10 +63,11 @@ class PkgUploadServices(MultiService):
6 """Container for package upload services."""
7
8 def __init__(self, oops_dir, oops_reporter, server_argv=None):
9- MultiService.__init__(self)
10+ super(PkgUploadServices, self).__init__()
11 self.oops_dir = oops_dir
12 self.oops_reporter = oops_reporter
13 self.server_argv = server_argv
14+ self._log_file = None
15
16 def _getLogObserver(self):
17 # We unfortunately have to clone-and-hack part of
18@@ -88,7 +89,7 @@ class PkgUploadServices(MultiService):
19 else:
20 if not logfilename:
21 logfilename = "txpkgupload.log"
22- logFile = LogFile.fromFullPath(
23+ self._log_file = logFile = LogFile.fromFullPath(
24 logfilename, rotateLength=None, defaultMode=0o644)
25 # Override if signal is set to None or SIG_DFL (0)
26 if not signal.getsignal(signal.SIGUSR1):
27@@ -110,8 +111,14 @@ class PkgUploadServices(MultiService):
28 return oops_observer.emit
29
30 def setServiceParent(self, parent):
31- MultiService.setServiceParent(self, parent)
32+ super(PkgUploadServices, self).setServiceParent(parent)
33 if isinstance(parent, Componentized):
34 # Customise the application's logging. We don't get much of an
35 # opportunity to do this otherwise.
36 parent.setComponent(log.ILogObserver, self._getLogObserver())
37+
38+ def disownServiceParent(self):
39+ if self._log_file is not None:
40+ self._log_file.close()
41+ self._log_file = None
42+ super(PkgUploadServices, self).disownServiceParent()
43diff --git a/src/txpkgupload/tests/test_plugin.py b/src/txpkgupload/tests/test_plugin.py
44index 610a27e..183de40 100644
45--- a/src/txpkgupload/tests/test_plugin.py
46+++ b/src/txpkgupload/tests/test_plugin.py
47@@ -230,6 +230,7 @@ class PkgUploadFixture(DeferringFixture):
48 # runner would, and start the service.
49 application = Application(self.service_maker.tapname)
50 self.service.setServiceParent(application)
51+ self.addCleanup(self.service.disownServiceParent)
52 self.observer = application.getComponent(log.ILogObserver, None)
53 log.addObserver(self.observer)
54 self.addCleanup(log.removeObserver, self.observer)

Subscribers

People subscribed via source and target branches

to all changes: