28 Apr
2020
28 Apr
'20
6:17 p.m.
On Tue, Apr 28, 2020 at 11:45:49AM -0700, Raymond Hettinger wrote:
It seems like you would get just about everything you want with one line:
once = lru_cache(maxsize=None)
But is it thread-safe? If you have a "once"ed expensive function with side-effects, and a second thread calls it before the first thread's initial call has completed, won't you end up executing the function twice? The documentation doesn't mention anything about thread-safety: https://docs.python.org/3/library/functools.html#functools.lru_cache -- Steven