Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit 2890066

Browse files
authored
Merge pull request #218 from frerich/friendly_timeout_errors
Friendlier error messages in case of cache access timeouts
2 parents d9af6b2 + 69c8a57 commit 2890066

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ clcache changelog
1111
which can be used to make clcache generate profiling information. The
1212
generated data can be processed into a final report using a new
1313
`showprofilereport.py` script.
14+
* Improvement: Timeout errors when accessing the cache now generate friendlier
15+
error messages mentioning the possibility to work around the issue using the
16+
`CLCACHE_OBJECT_CACHE_TIMEOUT_MS` environment variable.
1417

1518
## clcache 3.2.0 (2016-07-28)
1619

clcache.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class CacheLock(object):
221221
can be used in 'with' statements. """
222222
INFINITE = 0xFFFFFFFF
223223
WAIT_ABANDONED_CODE = 0x00000080
224+
WAIT_TIMEOUT_CODE = 0x00000102
224225

225226
def __init__(self, mutexName, timeoutMs):
226227
mutexName = 'Local\\' + mutexName
@@ -247,9 +248,15 @@ def acquire(self):
247248
result = windll.kernel32.WaitForSingleObject(
248249
self._mutex, wintypes.INT(self._timeoutMs))
249250
if result not in [0, self.WAIT_ABANDONED_CODE]:
250-
errorString = 'Error! WaitForSingleObject returns {result}, last error {error}'.format(
251-
result=result,
252-
error=windll.kernel32.GetLastError())
251+
if result == self.WAIT_TIMEOUT_CODE:
252+
errorString = \
253+
'Failed to acquire cache lock after {}ms; ' \
254+
'try setting CLCACHE_OBJECT_CACHE_TIMEOUT_MS environment variable to a larger value.'.format(
255+
self._timeoutMs)
256+
else:
257+
errorString = 'Error! WaitForSingleObject returns {result}, last error {error}'.format(
258+
result=result,
259+
error=windll.kernel32.GetLastError())
253260
raise CacheLockException(errorString)
254261
self._acquired = True
255262

0 commit comments

Comments
 (0)