From 819f4b1daa16ce88015d82359ec986aa6e5d7245 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 25 Aug 2013 18:47:47 +0530 Subject: [PATCH] Retry cleanup to avoid errors due to transient file locks on windows --- src/calibre/db/tests/base.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/tests/base.py b/src/calibre/db/tests/base.py index fae9ae944f..45f3eb39a4 100644 --- a/src/calibre/db/tests/base.py +++ b/src/calibre/db/tests/base.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import unittest, os, shutil, tempfile, atexit, gc +import unittest, os, shutil, tempfile, atexit, gc, time from functools import partial from io import BytesIO from future_builtins import map @@ -31,7 +31,13 @@ class BaseTest(unittest.TestCase): from calibre.utils.recycle_bin import restore_recyle restore_recyle() gc.collect(), gc.collect() - shutil.rmtree(self.library_path) + try: + shutil.rmtree(self.library_path) + except EnvironmentError: + # Try again in case something transient has a file lock on windows + gc.collect(), gc.collect() + time.sleep(2) + shutil.rmtree(self.library_path) def create_db(self, library_path): from calibre.library.database2 import LibraryDatabase2