Skip to content

Commit 7204c0a

Browse files
Cache: reduce sleep time (#504)
* Cache: reduce sleep time * Update cache.py * print warnings fix * restructure * add comment about our choice for the timeout
1 parent 8e10b18 commit 7204c0a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

pyopencl/cache.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,32 @@ def __init__(self, cleanup_m, cache_dir):
8888
except OSError:
8989
pass
9090

91+
# This value was chosen based on the py-filelock package:
92+
# https://github.com/tox-dev/py-filelock/blob/a6c8fabc4192fa7a4ae19b1875ee842ec5eb4f61/src/filelock/_api.py#L113
93+
# When running pyopencl in an application with multiple ranks
94+
# that share a cache_dir, higher timeouts can lead to
95+
# application stalls even with low numbers of ranks.
96+
# cf. https://github.com/inducer/pyopencl/pull/504
97+
wait_time_seconds = 0.05
98+
99+
# Warn every 10 seconds if not able to acquire lock
100+
warn_attempts = int(10/wait_time_seconds)
101+
102+
# Exit after 60 seconds if not able to acquire lock
103+
exit_attempts = int(60/wait_time_seconds)
104+
91105
from time import sleep
92-
sleep(1)
106+
sleep(wait_time_seconds)
93107

94108
attempts += 1
95109

96-
if attempts > 10:
110+
if attempts % warn_attempts == 0:
97111
from warnings import warn
98112
warn("could not obtain cache lock--delete '%s' if necessary"
99113
% self.lock_file)
100114

101-
if attempts > 3 * 60:
102-
raise RuntimeError("waited more than three minutes "
115+
if attempts > exit_attempts:
116+
raise RuntimeError("waited more than one minute "
103117
"on the lock file '%s'"
104118
"--something is wrong" % self.lock_file)
105119

0 commit comments

Comments
 (0)