summaryrefslogtreecommitdiff
path: root/fs/tempfs.py
diff options
context:
space:
mode:
authorrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-12-01 01:19:55 +0000
committerrfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f>2009-12-01 01:19:55 +0000
commit7aa784328d9c0c7ba3d0a283456e53b4692f9247 (patch)
tree734952d7ac7fec5e4c500ce17487740dc500b96d /fs/tempfs.py
parentf036682fabda4f47bbd31c0199018f9dde53c758 (diff)
downloadpyfilesystem-git-7aa784328d9c0c7ba3d0a283456e53b4692f9247.tar.gz
TempFS.close(): recover from temporarily locked resources on win32
Diffstat (limited to 'fs/tempfs.py')
-rw-r--r--fs/tempfs.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/fs/tempfs.py b/fs/tempfs.py
index 641b7f3..c62bc97 100644
--- a/fs/tempfs.py
+++ b/fs/tempfs.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python
import os
-from osfs import OSFS
+import time
import tempfile
+from fs.osfs import OSFS
from fs.errors import *
class TempFS(OSFS):
@@ -30,13 +31,27 @@ class TempFS(OSFS):
def __unicode__(self):
return unicode(self.__str__())
- @convert_os_errors
def close(self):
"""Removes the temporary directory.
+
This will be called automatically when the object is cleaned up by
Python. Note that once this method has been called, the FS object may
no longer be used.
"""
+ try:
+ self._close()
+ except ResourceLockedError:
+ # Give win32 a chance to clean up after itself
+ time.sleep(0.5)
+ self._close()
+
+ @convert_os_errors
+ def _close(self):
+ """Actual implementation of close().
+
+ This is a separate method so it can be re-tried in the face of
+ transient errors.
+ """
if not self._cleaned and self.exists("/"):
self._lock.acquire()
try: