On Sun, Apr 26, 2020 at 9:46 AM Alex Hall <alex.moj...@gmail.com> wrote:

> It's not clear to me why people prefer an extra function which would be
> exactly equivalent to lru_cache in the expected use case (i.e. decorating a
> function without arguments). It seems like a good way to cause confusion,
> especially for beginners. Based on the Zen, there should be one obvious way
> to do it.
>

I don't believe it is.  lru_cache only guarantees that you will get the
same result back for identical arguments, not that the function will only
be called once.  Seems to me if you call it, then in the middle of caching
the value, there's a thread change, you could get to the function wrapped
by lru_cache twice (or more times).  In order to implement once, it needs
to contain a thread lock to ensure its "once" moniker and support the
singleton pattern for which it is currently being used (apparently
incorrectly) in django and other places.  Am I understanding threading
correctly here?
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CLTSP32IKCVXZ2CG66XOU3CUWR2LZEYF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to