← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jml/launchpad/atexit-warning into lp:launchpad/devel

 

Jonathan Lange has proposed merging lp:~jml/launchpad/atexit-warning into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)


I'm sick of the atexit warning about the librarian teardown. This patch stops it.
-- 
https://code.launchpad.net/~jml/launchpad/atexit-warning/+merge/39403
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jml/launchpad/atexit-warning into lp:launchpad/devel.
=== modified file 'lib/canonical/librarian/testing/server.py'
--- lib/canonical/librarian/testing/server.py	2010-09-27 02:08:32 +0000
+++ lib/canonical/librarian/testing/server.py	2010-10-26 20:22:59 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Fixture for the librarians."""
@@ -11,9 +11,9 @@
     'LibrarianTestSetup',
     ]
 
+import atexit
 import os
 import shutil
-import tempfile
 import warnings
 
 from fixtures import Fixture
@@ -24,7 +24,6 @@
     get_pid_from_file,
     TacException,
     TacTestSetup,
-    two_stage_kill,
     )
 from canonical.librarian.storage import _relFileLocation
 
@@ -137,6 +136,18 @@
             return
         TacTestSetup.cleanUp(self)
 
+    def tearDownOnExit(self):
+        """Tell the librarian to shut down when Python exits."""
+        def tear_down():
+            # This is cleanUp(), but without the deprecation warning.  If
+            # Python provided a way of cancelling atexit calls, then we would
+            # just cancel the call on tearDown rather than silencing the
+            # DeprecationWarning.
+            if self._persistent_servers():
+                return
+            TacTestSetup.cleanUp(self)
+        atexit.register(tear_down)
+
     def clear(self):
         """Clear all files from the Librarian"""
         # Make this smarter if our tests create huge numbers of files

=== modified file 'lib/canonical/testing/layers.py'
--- lib/canonical/testing/layers.py	2010-10-22 09:49:44 +0000
+++ lib/canonical/testing/layers.py	2010-10-26 20:22:59 +0000
@@ -634,8 +634,8 @@
                     )
         the_librarian = LibrarianTestSetup()
         the_librarian.setUp()
+        the_librarian.tearDownOnExit()
         LibrarianLayer._check_and_reset()
-        atexit.register(the_librarian.tearDown)
 
     @classmethod
     @profiled


Follow ups