From 27645fa6a49c95f0f5b629cbadf281bfe7bff934 Mon Sep 17 00:00:00 2001
From: Jim Fulton <jim@zope.com>
Date: Sat, 12 May 2007 14:18:05 +0000
Subject: [PATCH] Added code to wait if attempts to remove the test dir fail on
 windows to give time for servers to stop, since windows won't let us remove
 files or directories if they are in use.

---
 src/ZODB/tests/util.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/ZODB/tests/util.py b/src/ZODB/tests/util.py
index 1e202739..9a861928 100644
--- a/src/ZODB/tests/util.py
+++ b/src/ZODB/tests/util.py
@@ -18,6 +18,7 @@ $Id$
 
 import os
 import shutil
+import sys
 import tempfile
 import time
 
@@ -46,11 +47,26 @@ class P(persistent.Persistent):
 def setUp(test):
     test.globs['__teardown_stack__'] = []
     tmp = tempfile.mkdtemp('test')
-    registerTearDown(test, lambda : shutil.rmtree(tmp))
+    registerTearDown(test, lambda : rmtree(tmp))
     here = os.getcwd()
     registerTearDown(test, lambda : os.chdir(here))
     os.chdir(tmp)
-    
+
+if sys.platform == 'win32':    
+    # On windows, we can't remove a directory of there are files upen.
+    # We may need to wait a while for processes to exit.
+    def rmtree(path):
+        for i in range(1000):
+            try:
+                shutil.rmtree(path)
+            except OSError:
+                time.sleep(0.01)
+            else:
+                break
+
+else:
+    rmtree = shutil.rmtree
+            
 def registerTearDown(test, func):
     test.globs['__teardown_stack__'].append(func)    
     
-- 
2.30.9