summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik M. Bray <erik.bray@lri.fr>2016-09-29 11:26:15 +0200
committerErik M. Bray <erik.bray@lri.fr>2016-09-29 11:26:15 +0200
commit64e3a7f11834c4800285802eb57429a45b582061 (patch)
treea4f1cf72f7310aa79337005b63d989cdbb162690
parent2578cb2393cdf9f89a5b631f38ea9854d78ccb01 (diff)
downloadpsutil-64e3a7f11834c4800285802eb57429a45b582061.tar.gz
Narrower condition for retrying wait_for_file
-rw-r--r--psutil/tests/__init__.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index f36c469c..351ffb14 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -62,6 +62,10 @@ if PY3:
else:
import imp as importlib
+if sys.platform.startswith('win'):
+ from winerror import ERROR_SHARING_VIOLATION
+
+
__all__ = [
# constants
'APPVEYOR', 'DEVNULL', 'GLOBAL_TIMEOUT', 'MEMORY_TOLERANCE', 'NO_RETRIES',
@@ -392,7 +396,14 @@ def wait_for_file(fname, timeout=GLOBAL_TIMEOUT, empty=False,
if delete_file:
os.remove(fname)
return data
- except (IOError, OSError):
+ except OSError as exc:
+ if not ((sys.platform.startswith('win') and
+ exc.winerror == ERROR_SHARING_VIOLATION) or
+ exc.errno == errno.ENOENT):
+ # In Windows deleting the temporary file can fail if some
+ # process is still holding it open, so retry in that case
+ raise
+
time.sleep(sleep_for)
sleep_for = min(sleep_for * 2, 0.01)
raise RuntimeError(