Commit 7aa78432 by rfkelly0

TempFS.close(): recover from temporarily locked resources on win32

parent f036682f
#!/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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment