Moved from *.__del__() to exclusive use of *.cleanup().
authorW. Trevor King <wking@drexel.edu>
Tue, 6 Oct 2009 01:00:34 +0000 (21:00 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 6 Oct 2009 01:00:34 +0000 (21:00 -0400)
*.__del__() is run some unspecified time after the refcount for an
object is reduced to zero.  Sometimes that means that the rest of the
world has already been deallocated, which makes life difficult,
especially when Python won't attempt to construct stack traces inside
*.__del__().  We were always (hopefully ;) calling del(*) anyway,
so we just replace those calls with *.cleanup()

becommands/init.py
libbe/arch.py
libbe/bugdir.py
libbe/utility.py
libbe/vcs.py

index 1125d937e158940fb5eb41ddf8ea5f488fe7f859..a6098ba191306c17a72fe59051ccd0e18596ba19 100644 (file)
@@ -32,7 +32,7 @@ def execute(args, manipulate_encodings=True):
     >>> execute(['--root', dir.path], manipulate_encodings=False)
     No revision control detected.
     Directory initialized.
-    >>> del(dir)
+    >>> dir.cleanup()
 
     >>> dir = utility.Dir()
     >>> os.chdir(dir.path)
index ab551729da670de122e9de31f91bd155710a095b..c2d7cdec7234c3356b4b7b427a196b9866ae9833 100644 (file)
@@ -70,7 +70,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch archive in the directory PATH.  This
         archive will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_archive
+          cleanup->_vcs_cleanup->_remove_archive
         """
         # http://regexps.srparish.net/tutorial-tla/new-archive.html#Creating_a_New_Archive
         assert self._archive_name == None
@@ -112,7 +112,7 @@ class Arch(vcs.VCS):
         """
         Create a temporary Arch project in the directory PATH.  This
         project will be removed by
-          __del__->cleanup->_vcs_cleanup->_remove_project
+          cleanup->_vcs_cleanup->_remove_project
         """
         # http://mwolson.org/projects/GettingStartedWithArch.html
         # http://regexps.srparish.net/tutorial-tla/new-project.html#Starting_a_New_Project
index c4f0f9192b327035f90c8a88689f60a6044d6ccb..532416315b394e60c6d17f5f2529831c026a5848 100644 (file)
@@ -305,6 +305,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.root = self._find_root(root)
         else:
             if not os.path.exists(root):
+                self.root = None
                 raise NoRootEntry(root)
             self.root = root
         # get a temporary vcs until we've loaded settings
@@ -324,9 +325,6 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
             self.vcs = vcs
             self._setup_user_id(self.user_id)
 
-    def __del__(self):
-        self.cleanup()
-
     def cleanup(self):
         self.vcs.cleanup()
 
@@ -339,6 +337,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         then only if sink_to_existing_root == True.
         """
         if not os.path.exists(path):
+            self.root = None
             raise NoRootEntry(path)
         versionfile=utility.search_parent_directories(path,
                                                       os.path.join(".be", "version"))
@@ -349,6 +348,7 @@ settings easy.  Don't set this attribute.  Set .vcs instead, and
         else:
             beroot = utility.search_parent_directories(path, ".be")
             if beroot == None:
+                self.root = None
                 raise NoBugDir(path)
             return beroot
 
@@ -671,7 +671,7 @@ class SimpleBugDir (BugDir):
                     assert_new_BugDir=assert_new_BugDir,
                     allow_vcs_init=vcs_init,
                     manipulate_encodings=False)
-        if sync_with_disk == True: # postpone cleanup since dir.__del__() removes dir.
+        if sync_with_disk == True: # postpone cleanup since dir.cleanup() removes dir.
             self._dir_ref = dir
         bug_a = self.new_bug("a", summary="Bug A")
         bug_a.creator = "John Doe <jdoe@example.com>"
index aafbf8d164c5d77b446114d28347299c450c9b38..1e4351603c1d1a0bd3b9b94bc628bf46eefcba1d 100644 (file)
@@ -58,13 +58,10 @@ class Dir (object):
     "A temporary directory for testing use"
     def __init__(self):
         self.path = tempfile.mkdtemp(prefix="BEtest")
-        self.rmtree = shutil.rmtree # save local reference for __del__
         self.removed = False
-    def __del__(self):
-        self.cleanup()
     def cleanup(self):
         if self.removed == False:
-            self.rmtree(self.path)
+            shutil.rmtree(self.path)
             self.removed = True
     def __call__(self):
         return self.path
index a1d302264700e7993351b3ddda914b8ca50294ab..6975a83a9e7a9aa53e09e4b8588a18f7f2e58468 100644 (file)
@@ -50,7 +50,7 @@ def _get_matching_vcs(matchfn):
         vcs = module.new()
         if matchfn(vcs) == True:
             return vcs
-        del(vcs)
+        vcs.cleanup()
     return VCS()
     
 def vcs_by_name(vcs_name):
@@ -124,8 +124,6 @@ class VCS(object):
         self._duplicateBasedir = None
         self._duplicateDirname = None
         self.encoding = encoding
-    def __del__(self):
-        self.cleanup()
 
     def _vcs_help(self):
         """
@@ -674,7 +672,7 @@ class VCSTestCase(unittest.TestCase):
         setup_vcs_test_fixtures(self)
 
     def tearDown(self):
-        del(self.vcs)
+        self.vcs.cleanup()
         super(VCSTestCase, self).tearDown()
 
     def full_path(self, rel_path):